Share on Google+Share on Google+

loadModule and unloadModule method in Flex 3

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.


loginmodule.mxml code

<?xml version="1.0"?>

<mx:Module xmlns:mx="" width="100%" height="100%" >


import mx.controls.Alert;

private function submit():void{

var name:String = loginnametext.text;

var password:String = loginpasswordtext.text;

if(name!="" && password!=""){"User Name is :" + name);

loginnametext.text = "";

loginpasswordtext.text = "";


else{"Enter correct name and password!");





<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 width="301">

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

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



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




main.mxml code

<?xml version="1.0"?>

<mx:Application xmlns:mx="">



import mx.modules.*;

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

if (!ml.url) {

ml.url = s;





public function unload(ml:ModuleLoader):void {





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




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


1. Output For loadModule() method:-

2. Output for unloadModule() method:-


Download this code


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.


Advertisement null