N'importe quel module formé de cette manière est importable dans une application Flex:
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300" backgroundColor="#43BC3D">
<mx:ComboBox x="104" y="67"></mx:ComboBox>
</mx:Module>
Exemple :
LoadModule.swf => Cet exemple charge le module "module.swf" ou "canvasModule.swf" (boite de saisie), la croix ferme le module
Le chargement se fait de cette façon:
<?xml version="1.0"?>
<!— modules/ASModuleLoaderApp.mxml —>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.states.SetProperty;
import mx.containers.HBox;
import mx.controls.Button;
import flash.events.MouseEvent;
import mx.modules.*;
public function removeModule(m:ModuleLoader):void {
m.unloadModule();
}
public function newModule(s:String):void
{
var hbox:HBox = new HBox();
panel.addChild(hbox);
var btn:Button = new Button();
btn.addEventListener(MouseEvent.CLICK, supprimer);
btn.label="X";
hbox.addChild(btn);
var newM:ModuleLoader = new ModuleLoader();
newM.name="newM";
hbox.addChild(newM);
newM.url = s;
newM.loadModule();
}
public function supprimer(e:MouseEvent):void
{
var btn:Button = Button(e.currentTarget);
removeModule((ModuleLoader)(btn.parent.getChildByName("newM")));
btn.parent.parent.removeChild(btn.parent);
}
]]>
</mx:Script>
<mx:Panel title="Module Example" id="panel"
height="90%"
width="90%"
paddingTop="10"
paddingLeft="10"
paddingRight="10"
paddingBottom="10"
>
<mx:VBox id="vb2" label="Form Module">
<mx:Button
label="Load"
click="createModule(formModuleLoader, monModule.text)"
visible="false"
/>
<mx:Button
label="Unload"
click="removeModule(formModuleLoader)"
visible="false"
/>
<mx:Button
label="New"
click="newModule(monModule.text)"
/>
<mx:TextInput id="monModule" text="module.swf"/>
<mx:ModuleLoader id="formModuleLoader"/>
</mx:VBox>
</mx:Panel>
</mx:Application>
Les sources:
module.mxml
LoadModule.mxml





