Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Module PureMVC deferred initalization issue  (Read 2644 times)
dancantong
Jr. Member
**
Posts: 12


View Profile Email
« on: September 24, 2009, 02:33:23 »

Hi!
I'm developing a Flex3 multicore PureMVC application and I'm having the following issue.
From the Shell I have to show a module with a certain view. The active view is set throught a method published in the module interface. Before invoking the method, I have to wait till Module is ready with ModuleEvent.READY event. When this occurrs, I invoke the method on the module but the READY event fires before the Module creationComplete is fired that is where I initialize PureMVC in the module. So I can't access PureMVC to set init view in the module.

Could anyone tell me If I'm doing anything wrong or suggest me a solution to this problem?

Thanks in advance,

Daniel.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: September 24, 2009, 08:12:09 »

Instead of using the creationComplete handler to kick off your PureMVC startup inside the module, invoke it explicitly from the outside. That way you control the order of events. For the example module code below, this would amount to:

1) Load the module and listen for ModuleEvent.READY.
2) Add a listener to the module for a SharedConstants.CORE_READY event. (you define this constants file).
3) Invoke the ICustomModule interface method 'initializeModule()' (you define this interface).
4) Remove the listener for CORE_READY.
5) Proceed to do stuff with the module.

:

public class MyModule extends ModuleBase implements ICustomModule
{
   public static constant NAME:String = "MyModule";
   public var moduleID:String;

   private var facade:IFacade;
   private static var instances:Number = 0;
 
  /**
   * Get the next Module ID.
   */
   public static const getNextID():String
   {
       moduleID = NAME+String( instances++ );
       return moduleID;
   }
 
  /**
   * Initialize the Module.
   */
   public function initializeModule():void
   {
      this.facade = MyModuleFacade.getInstance( MyModule.getNextID() );
      MyModuleFacade(facade).startup(this);
      dispatchEvent(new Event(SharedConstants.CORE_READY));
   }

}

-=Cliff>
Logged
Pages: [1]
Print