Hi everybody.
My company using flex 3 and now upgrade to flex 4. I have the problem when using module in flex 4.
I create module in Flash Builder, and the default, Flash Builder create module by extend mx:Module. In this module i creaate ComboBox(mx) and Button(spark) for example.
In the main application, the first, if i using ModuleLoader tag and specify url of ModuleLoader than application load module ok. But the project is too large, and main application can not load static module. So i define module in xml file. If i using ModulerManager.getModule(url).load() then error occur. Or if i loaded completly, when module init it throw error that skin for control that i create in module has not skin.The problem occur when i do not set skin class style. And it not occur if i set skin class style.
So, what i need do before add module into main application, i do not want specify skinclass for all control in my module(i think the default skin load, but not).
Anyone please help me.
Thanks.
Many thanks Flex harUI.
I have created module in mxml file. You can see the Test folder in attach file. The problem do not occur in flex 3(may be flex 3 do not using skin).
Please point that the problem occur when you load module using Loader or ModuleLoader in script tag. It does not occur if you using ModuleLoader tag.
Because i need load module difference server, so i can not use ModuleLoader tag.
Please check in attach file!
Here is my module:
<?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/halo"
layout="vertical" width="100%" height="100%">
<mx:ComboBox borderColor="0xFF00FF" borderThickness="3">
<mx:dataProvider>
<fx:Array>
<fx:String>Item 1</fx:String>
<fx:String>Item 2</fx:String>
<fx:String>Item 3</fx:String>
</fx:Array>
</mx:dataProvider>
</mx:ComboBox>
<s:Button label="Button">
</mx:Module>
The main application:
<?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/halo"
minWidth="1024" minHeight="768"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Style>
@namespace mx "library://ns.adobe.com/flex/halo";
@namespace s "library://ns.adobe.com/flex/spark";
mx|ComboBox {
color: "0xFF00FF";
}
s|Button {
skin-class: "spark.skins.default.ButtonSkin";
}
</fx:Style>
<fx:Script>
<![CDATA[
import mx.modules.ModuleLoader;
import mx.modules.IModuleInfo;
import mx.modules.ModuleManager;
import mx.modules.Module;
import mx.core.IFlexModuleFactory;
import mx.events.ModuleEvent;
import mx.events.FlexEvent;
private var module:IModuleInfo;
protected function application1_creationCompleteHandler(event:FlexEvent):void {
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
ldr.load(new URLRequest('MyModule.swf'));
//var moduleLoader:ModuleLoader = new ModuleLoader();
//moduleLoader.url = "MyModule.swf";
//moduleLoader.addEventListener(ModuleEvent.READY, onReadyHandler);
//moduleLoader.loadModule();
}
private function onCompleteHandler(evt:Event):void {
(evt.currentTarget as LoaderInfo).content.addEventListener(ModuleEvent.READY, onReadyHandler);
}
private function onReadyHandler(evt:ModuleEvent):void {
//var moduleLoader:ModuleLoader = (evt.currentTarget as ModuleLoader);
//var module:Module = moduleLoader.moduleFactory.create() as Module;
var module: Module = (evt.currentTarget as IFlexModuleFactory).create() as Module;
this.addElement(module);
}
]]>
</fx:Script>
<!--ModuleLoader url="MyModule.swf"/-->
</s:Application>
Please test with Loader as code and ModuleLoader tag. Also change skinclass of button in MyModule for test.
Thanks much.
I have tried to use keep-all-type-selectors option compiler by add it to additional args compiler. All components in spark pagekage load and render ok with both Loader and ModuleLoader. But the halo component for example combobox not render, i can not see combobox when i use Loader. And when i use ModuleLoader, all things are ok. So what should i do when i use Loader by actionscript code.
Please note that when add this additional option compiler, the size of main app increase(my example is 1.3Mb, it is too large), the module size is 258kb.
Thank for your solution, Flex harUI.
Here is my updated code:
MyModule.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/halo"
layout="absolute" width="100%" height="100%">
<mx:ComboBox x="241" y="83">
<mx:dataProvider>
<fx:Array>
<fx:String>Item 1</fx:String>
<fx:String>Item 2</fx:String>
<fx:String>Item 3</fx:String>
</fx:Array>
</mx:dataProvider>
</mx:ComboBox>
<s:Button label="Button" x="243" y="132"/>
<s:HScrollBar x="246" y="191" width="280"></s:HScrollBar>
</mx:Module>
Main.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/halo"
minWidth="1024" minHeight="768"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.modules.ModuleLoader;
import mx.modules.IModuleInfo;
import mx.modules.ModuleManager;
import mx.modules.Module;
import mx.core.IFlexModuleFactory;
import mx.events.ModuleEvent;
import mx.events.FlexEvent;
private var info:IModuleInfo;
protected function application1_creationCompleteHandler(event:FlexEvent):void {
info = ModuleManager.getModule('MyModule.swf');
info.addEventListener(ModuleEvent.READY, onModuleReadyHandler);
info.load();
}
private function onModuleReadyHandler(evt:ModuleEvent):void {
this.addChild(info.factory.create() as DisplayObject);
}
]]>
</fx:Script>
</s:Application>
Beside, i add previouse additional option compiler argument for main app.
Here is my result when run app:
VerifyError: Error #1014: Class mx.modules::Module could not be found.
at flash.display::MovieClip/nextFrame()
at mx.core::FlexModuleFactory/deferredNextFrame()[E:\dev\beta1\framework s\projects\framework\src\mx\core\FlexModuleFactory.as:530]
at mx.core::FlexModuleFactory/update()[E:\dev\beta1\frameworks\projects\ framework\src\mx\core\FlexModuleFactory.as:358]
at mx.core::FlexModuleFactory/moduleCompleteHandler()[E:\dev\beta1\frame works\projects\framework\src\mx\core\FlexModuleFactory.as:605]
By using ModuleManager at link:
I was able to compile and run your application by changing one line of the application. I changed
this.addChild(info.factory.create() as DisplayObject);
to
this.contentGroup.addElement(info.factory.create() as IVisualElement);
Compiling modules to load RSLs is not necessary, assuming the main application is loading all the RSLs the module needs. But you should not need to compile your application with -static-rsls=true to avoid errors. If your errors go away when using -static-rsls=true it means there was an error loading the RSLs. Check your Flash Player log to see if there are other errors.
I should have said I didn't get the same VerifyError that you did. I compiled the application and module within Flash Builder. My guess is you are compiling the module with framework.swc on the external library path but the main application is not loading the framework RSL. Try removing any extra libraries you have on the external library path when compiling your module.
One improvement to my change. You don't need to specify this.contentGroup. The application knows the content group to add the module to so the line could have been written like this:
this
I have built module and application inside Flash Builder by select Project -> Build Project. Not use command line or other task before.
Here is my last result and i will use one of them:
Using ModuleManager:
Remove all except default -locale en_US at Additional Compiler Arguments at Properties of Project -> Build and Run OK.
Using Loader:
Add to Additional Compiler Arguments: -keep-all-type-selectors=true
Change Flex Builder Path -> Library Path -> Runtime share library(RSL)
- Build and run OK
(Using this way, flash builder auto generate some rsl file(swf), but the size of app and module are smaller than).
Manty thank Flex haRui and Darrell Loverin for your helps.
![]()
Since my last post I built an entire spark application as a module of a bigger spark application, and everything is working perfectly well. The only difference I see (which is expected) is that it takes the app longer to load with a module, probably because the module is being loaded using a separate http call. Over-all it was smooth sailing using modules with spark and halo.
Alex,
Is there any more information posted somewhere on the limitations of Spark components within Modules?
I tried searching the bugbase, and the version filtering is not very intuitive to say the least (the drop down selections do not seem to match what is displayed as the version in the results).
We're having trouble with setting the layout to "absolute" in an essentially Spark module (of course, the module is Halo, but all of the children are Spark components). I should probably note that the module is sub-classed (actually a couple of levels) and the children are added dynamically.
In the constructor (of the module sub-class), when the layout is set to "absolute" the module is not renderer on the stage. If we remove that layout = "absolute" everything displays as it should.
Any thoughts?
Thanks!
Kirk
Recent nightly builds should not have functional limitations. That said, I'm sure there are some that we don't know about or I'm not remembering, so if you run into one, file a bug or post a simple test case in the forums.
But for sure, use -static-rsls when compiling modules if you are using rsl-linkage for the main app (which is the default).
Alex Harui
Flex SDK Developer
Adobe Systems Inc.
North America
Europe, Middle East and Africa
Asia Pacific
Copyright © 2012 Adobe Systems Incorporated. All rights reserved.
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).