Home Tutorial Flex Flex-components loadModule and unloadModule method in Flex 3

 
 

Share on Google+Share on Google+
loadModule and unloadModule method in Flex 3
Posted on: July 12, 2010 at 12:00 AM
Advertisement
ModuleLoader API provide methods loadModule() for load module and unloadModule() for unload modules

loadModule and unloadModule methods for modules:-

 ModuleLoader API  provide methods loadModule() for load module and unloadModule() for unload modules. These methods take no parameters. These methods load or unload module on the bases of current url property. In this example user can see how to load or unload module on button click events.

Example:-

loginmodule.mxml 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" title="Login Module">

<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.mxml code

<?xml version="1.0"?>

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

<mx:Script>

<![CDATA[

import mx.modules.*;

public function load(ml:ModuleLoader, s:String):void {

if (!ml.url) {

ml.url = s;

return;

}

ml.loadModule();

}

public function unload(ml:ModuleLoader):void {

ml.unloadModule();

}

]]>

</mx:Script>

<mx:Panel title="Load / Unload method example" height="50%" width="50%">

<mx:VBox label="Login Module">

<mx:Button label="Load" click="load(loginmodule, label1.text)"/>

<mx:Button label="Unload" click="unload(loginmodule)"/>

<mx:Label id="label1" text="loginmodule.swf"/>

<mx:ModuleLoader id="loginmodule"/>

</mx:VBox>

</mx:Panel>

</mx:Application>

After compile these code after that run main.swf and show result.

Output:-

1. Output For loadModule() method:-

2. Output for unloadModule() method:-

 

Download this code

Advertisement

Related Tags for loadModule and unloadModule method in Flex 3:


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.

Posted on: July 12, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com