Skip to main content
Participant
March 19, 2011
Question

Problem with module lazy loading in flex 3

  • March 19, 2011
  • 1 reply
  • 2857 views

Hi every body!

I have some problems with Module lazy loading. I am using flex 3.5, Module-flex3-0.14, parsley 3.2.

I can't get the LazyModuleLoadPolicy working correctly.

In my main application (the one that loads the modules), my parsley context is the following:

        <cairngorm:LazyModuleLoadPolicy objectId="lazyLoadPolicy" type="{ OpenViewMessage }" />      <cairngorm:ModuleMessageInterceptor type="{ OpenViewMessage }"/>            <cairngorm:ParsleyModuleDescriptor objectId="test"           url="TestModule.swf"           applicationDomain="{ClassInfo.currentDomain}"      />

And to load my module:

[Inject(id="test")] [Bindable] public var test:IModuleManager;

<core:LazyModulePod      id="moduleLoader"      moduleManager="{test}"      moduleId="testModule" />

with  LazyModulePod.mxml:

<mx:Canvas     xmlns:mx="http://www.adobe.com/2006/mxml"     xmlns:module="com.adobe.cairngorm.module.*"     xmlns:parsley="http://www.spicefactory.org/parsley">     <mx:Script>         <![CDATA[             import com.adobe.cairngorm.module.ILoadPolicy;             import com.adobe.cairngorm.module.IModuleManager;             [Bindable]             public var moduleId:String;             [Bindable]             public var moduleManager:IModuleManager;             [Bindable]             [Inject(id="lazyLoadPolicy")]             public var lazyLoadPolicy:ILoadPolicy;                     ]]>     </mx:Script>     <parsley:Configure/>     <module:ViewLoader id="moduleLoader"         moduleId="{ moduleId }"         moduleManager="{ moduleManager }"         loadPolicy="{lazyLoadPolicy}">          <!--<module:loadPolicy>               <module:BasicLoadPolicy/>          </module:loadPolicy>-->     </module:ViewLoader> </mx:Canvas>

OpenViewMessage.as in a swc:

public class OpenViewMessage     {         private var _moduleId:String;         private var _viewId:String;         public function OpenViewMessage(moduleId:String, viewId:String)         {             this._moduleId = moduleId;             this._viewId = viewId;         }                 public function get viewId():String{             return _viewId;      }                         [ModuleId]         public function get moduleId():String         {             return _moduleId;         }     }

In another flex project, my module context is:

<mx:Object      xmlns:mx="http://www.adobe.com/2006/mxml"      xmlns:controler="com.cegedim.myit.controler.*">

     <controler:WindowControler/>       </mx:Object>

The module implements IParsleyModule

<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"      implements="com.adobe.cairngorm.module.IParsleyModule"      xmlns:spicefactory="http://www.spicefactory.org/parsley">      <mx:Script>           <![CDATA[                import org.spicefactory.parsley.flex.FlexContextBuilder;                import com.adobe.cairngorm.module.IParsleyModule;                                public function get contextBuilder():ContextBuilderTag             {                 return contextBuilderTag;             }           ]]>      </mx:Script>            <spicefactory:ContextBuilder  id="contextBuilderTag" config="{ MyITTestModuleContext }"/>            <spicefactory:Configure/>       </mx:Module>

and the WindowControler:

public class WindowControler {      public function WindowControler(){}            [Init]         public function initialize():void         {             Alert.show("Module Initialized");         }                 [MessageHandler(scope="local")]         public function openViewMessageHandler(message:OpenViewMessage):void         {             Alert.show("Opening view " + message.viewId + " in the module " + message.moduleId);         } }

If i uncomment the basicLoadPolicy in LazyModulePod.mxml and remove the lazyModuleLoadPolicy, everything works fine. The module is loaded when it's added to stage and it receives correctly messages dispatched to it. But with the lazy policy the module never loads.

I may have missed something or there is somthing i don't understand because i tried the ModuleTest provided in example in cairngorm sources. It works fine (i mean loading the moduleA2 when receiving a message), but if i replace the change the lazyModulePolicy to listen to broadcasted messages instead of a pingMessage, the module never loads too.

    <cairngorm:LazyModuleLoadPolicy objectId="lazyLoadPolicy" type="{ BroadcastMessage }" />         <cairngorm:ModuleMessageInterceptor         type="{ BroadcastMessage }" moduleRef="moduleA" />

public class BroadcastMessage {     public function BroadcastMessage()     {     } }

If someone has any clue, i'll be happy to test it 😃

Thanks.

This topic has been closed for replies.

1 reply

Participant
March 25, 2011

Hello, back on my issue, i tested a little bit more the message dispaching.

I read the lazyLoadPolicy class and noticed that it always has to have a ModuleId property in the message to work, that's why the broadcast message didn't work to awake the module with the lazy loading policy.

So i added copy of my module:

     <cairngorm:ParsleyModuleDescriptor objectId="test"           url="TestModule.swf"           applicationDomain="{ClassInfo.currentDomain}"      />      <cairngorm:ParsleyModuleDescriptor objectId="testbis"           url="TestModuleBis.swf"           applicationDomain="{ClassInfo.currentDomain}"      />     

Set them both with a basicLoadPolicy, and tries to dispatch a message to only one of them using the ModuleId metatag. I then noticed that both modules received the message and not only the one i expected.

I then changed the ModuleMessageInterceptor configuration to dispatch to only one kind of module:

<cairngorm:ModuleMessageInterceptor type="{ OpenViewMessage }" moduleRef="test"/>

and this worked as expected. Only the first module catched the message. I am obiously messing with the ModuleId metatag but i cannot see what's wrong...

I compiled with

-keep-as3-metadata+=ModuleId

but this hasn't changed anything...