Share on Google+Share on Google+

ModuleManager for load or unload module in Flex 3

Advertisement
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"/>

</mx:HBox>

<mx:HBox>

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

</mx:HBox>

</mx:Panel>

</mx:Module>

main.swf code

<?xml version="1.0"?>

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

creationComplete="initApp()">

<mx:Script>

<![CDATA[

import mx.events.ModuleEvent;

import mx.modules.ModuleManager;

import mx.modules.IModuleInfo;

public var moduleinfo:IModuleInfo;

private function initApp():void {

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

moduleinfo.addEventListener(ModuleEvent.READY, moduleEventHandler);

moduleinfo.load();

}

private function moduleEventHandler(e:ModuleEvent):void {

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

}

]]>

</mx:Script>

<mx:VBox id="loginbox"/>

</mx:Application>

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

Output:-

Download this code

Advertisements

Posted on: July 12, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.