Skip navigation
Alex Duperet
Currently Being Moderated

Problem with module lazy loading in flex 3

Mar 19, 2011 12:50 PM

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.

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points