ModuleManager for load or unload module in Flex 3


 

ModuleManager for load or unload module in Flex 3

In this example, we will used module manager to load and unload modules in the application

In this example, we will used module manager to load and unload modules in the application

Load module with the help of ModuleManager class:-

In this example, we will used module manager to load and unload modules in the application. It is loaded module with the help of  IModuleInfo interface by using the ModuleManager getModule() method that's provide the reference of the module. After that user can used load() method to load module.

Example:-

loginmodule.swf code

<?xml version="1.0"?>

<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" >

<mx:Script><![CDATA[

import mx.controls.Alert;

private function submit():void{

var name:String = loginnametext.text;

var password:String = loginpasswordtext.text;

if(name!="" && password!=""){

Alert.show("User Name is :" + name);

loginnametext.text = "";

loginpasswordtext.text = "";

}

else{

Alert.show("Enter correct name and password!");

}

}

]]>

</mx:Script>

<mx:Panel id="loginpanel" height="200" width="328">

<mx:HBox width="302">

<mx:Label id="loginname" text="Enter name "/>

<mx:TextInput id="loginnametext"/>

</mx:HBox>

<mx:HBox width="301">

<mx:Label id="loginpassword" text="Enter password"/>

<mx:TextInput id="loginpasswordtext" displayAsPassword="true"/>

0

</mx:HBox>

<mx:HBox>

<mx:Button label="Submit" click="submit()"/>

1

</mx:HBox>

</mx:Panel>

</mx:Module>

2

main.swf code

<?xml version="1.0"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

3

creationComplete="initApp()">

<mx:Script>

<![CDATA[

4

import mx.events.ModuleEvent;

import mx.modules.ModuleManager;

import mx.modules.IModuleInfo;

5

public var moduleinfo:IModuleInfo;

6

private function initApp():void {

moduleinfo = ModuleManager.getModule("loginmodule.swf");

moduleinfo.addEventListener(ModuleEvent.READY, moduleEventHandler);

7

moduleinfo.load();

}

private function moduleEventHandler(e:ModuleEvent):void {

8

loginbox.addChild(moduleinfo.factory.create() as DisplayObject);

}

]]>

9

</mx:Script>

<mx:VBox id="loginbox"/>

</mx:Application>

0

In this example you can see how to use module manager for the module based application.

Output:-

1

Download this code

Ads