Inconsistent behavior of my code with the cairngorm 3 module Library
Hi everybody,
I'm trying to use the cairngorm 3 module library based on the ModuleTest example project and experiencing problems with the LazyModuleLoadPolicy :
when compiling my test project, 2 randoms behaviors can be observed :
1 - the module is loaded automatically.
2 - the module is not loaded and the message supposed trigger the loading has no effects when it's dispatched.
I spent hours on the case but was unable to figure out the problem.
Here's my very simple test project :
lazyLoading.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:parsley="http://www.spicefactory.org/parsley" xmlns:cairngorm="http://ns.adobe.com/cairngorm">
<fx:Declarations>
<parsley:ContextBuilder>
<cairngorm:CairngormModuleSupport />
<parsley:FlexConfig type="{applicationContext}" />
</parsley:ContextBuilder>
<parsley:Configure />
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.adobe.cairngorm.module.ILoadPolicy;
import com.adobe.cairngorm.module.IModuleManager;
import mx.core.mx_internal;
import mx.modules.ModuleManager;
[Bindable]
[Inject(id="testModule")]
public var testModuleManager:IModuleManager;
[Bindable]
[Inject(id="lazyLoadPolicy")]
public var lazyLoadPolicy:ILoadPolicy;
[MessageDispatcher]
public var dispatcher:Function;
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:Button label="Charger le module" click="{dispatcher(new ModuleMessage('testModule') )}" />
<cairngorm:ModuleViewLoader id="Module" loadPolicy="{lazyLoadPolicy}" moduleManager="{testModuleManager}" skinClass="com.adobe.cairngorm.module.ModuleViewLoaderSkin" />
</s:Application>applicationContext.mxml
<?xml version="1.0" encoding="utf-8"?>
<fx:Object
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:cairngorm="http://ns.adobe.com/cairngorm" >
<fx:Script>
<![CDATA[
import org.spicefactory.lib.reflect.ClassInfo;
]]>
</fx:Script>
<fx:Declarations>
<cairngorm:ParsleyModuleDescriptor
objectId="testModule"
url="testModule.swf"
applicationDomain="{ClassInfo.currentDomain}" />
<cairngorm:ModuleMessageInterceptor type="{ModuleMessage}" />
<cairngorm:LazyModuleLoadPolicy objectId="lazyLoadPolicy" type="{ModuleMessage}" />
</fx:Declarations>
</fx:Object>ModuleMessage.as
package
{
public class ModuleMessage
{
private var _moduleId:String;
public function ModuleMessage(moduleId:String)
{
this._moduleId = moduleId;
trace("Module message with moduleId = " + moduleId + " dispatched");
}
[ModuleId]
public function get moduleId():String
{
return _moduleId;
}
}
}testModule.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="400" height="300" xmlns:parsley="http://www.spicefactory.org/parsley" >
<fx:Declarations>
<parsley:Configure />
</fx:Declarations>
<fx:Script>
<![CDATA[
[MessageHandler(scope="local")]
public function moduleMessageHandler(moduleMessage:ModuleMessage):void
{
trace(moduleMessage.moduleId);
}
]]>
</fx:Script>
<s:Label color="#FF0000" text="module loaded" />
</mx:Module>I'm using flex 4.5.1 with module-0.17.swc, parsley 2.4.1.swc and spiclelib 2.4.0.swc
You can, if you want, download my .fxp project here
I'm really stuck. After spending hours on it, I can't figure out the problem in my code.
Vincent.
