PureMVC Architects Lounge

PureMVC Manifold => MultiCore Version => Topic started by: dancantong on September 24, 2009, 02:33:23



Title: Module PureMVC deferred initalization issue
Post by: dancantong 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.


Title: Re: Module PureMVC deferred initalization issue
Post by: puremvc 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>