F Lex Of Modules The technology can be Flex ProgramOne SWF File, which cannot run independently from the program, but can be shared among multiple programs. Flex Of Modules Technology divides applications into small blocks and modules, and the main program dynamically loads the required modules. The main program does not load all modules at startup. When the user does not interact with the module, it does not need to load the module, and it can unload the module and release the memory and resources when the module does not need it.
FlexOfModulesThe technology has the following advantages:
LetSWFThe initial download size is smaller.
Shorter loading time
Better encapsulation of applications.
Interface Rendering
Application Development
Add moduleloader control, and passed in the calculated parameter value
View code
<? XML version = "1.0" encoding = "UTF-8"?>
<S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009"
Xmlns: S = "Library: // ns.adobe.com/flex/spark"
Xmlns: MX = "Library: // ns.adobe.com/flex/mx" minwidth = "955" minheight = "600">
<FX: declarations>
<! -- Place non-visual elements (such as services and value objects) Here -->
</FX: declarations>
<S: layout>
<S: verticallayout/>
</S: layout>
<FX: SCRIPT>
<! [CDATA [
[Bindable]
Public VaR Result: String = New String ();
Private VaR Moduleinstance: Object ; // Used to save the attached instance reference
Protected Function Btnadd_clickhandler (Event: mouseevent): void
{
// Reload
Mdlcalculate. unloadmodule ();
Mdlcalculate. loadmodule ();
}
Private Function Moduleready (): void {
Moduleinstance = mdlcalculate. Child;
Moduleinstance. Calculate (txta. Text, txtb. Text );
}
]>
</FX: SCRIPT>
<Mx: Form>
<Mx: formitem label = "A:">
<S: textinput id = "txta"/>
</MX: formitem>
<Mx: formitem label = "B:">
<S: textinput id = "txtb"/>
</MX: formitem>
<Mx: formitem>
<S: button label = "add" id = "btnadd" Click = "btnadd_clickhandler (event)"/>
</MX: formitem>
</MX: Form>
<Mx: moduleloader id = "mdlcalculate" url = "module \ calculatemodule.swf" Ready = "moduleready ()" width = "400" Height = "120"/>
<Mx: Form>
<Mx: formitem label = "Calculation Result:">
<S: textinput text = "{result}"/>
</MX: formitem>
</MX: Form>
</S: Application>
Module Development
Create a folder Module , Create in this folder Mxml Module Calculatemodule. mxml
View code
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: module xmlns: FX = "http://ns.adobe.com/mxml/2009"
Xmlns: S = "Library: // ns.adobe.com/flex/spark"
Xmlns: MX = "Library: // ns.adobe.com/flex/mx" layout = "absolute" width = "100%" Height = "100%">
<FX: declarations>
<! -- Place non-visual elements (such as services and value objects) Here -->
</FX: declarations>
<FX: SCRIPT>
<! [CDATA [
[Bindable]
Public VaR Addresult: String = New String ();
Public Function Calculate (: String , B: String ): Void
{
Try
{
Addresult = String ( Number (A) + Number (B ));
}
Catch (Ex: Error)
{
}
}
Protected Function Btnsub_clickhandler (Event: mouseevent): void
{
// Subtract and submit the result
This. parentdocument. Result = String ( Number (Addresult )- Number (Txtc. Text ));
}
]>
</FX: SCRIPT>
<Mx: Form>
<Mx: formitem label = "Calculation Result:">
<S: textinput id = "txtresult" text = "{addresult}"/>
</MX: formitem>
<Mx: formitem label = "C">
<S: textinput id = "txtc"/>
</MX: formitem>
<Mx: formitem>
<S: button label = "Subtract" id = "btnsub" Click = "btnsub_clickhandler (event)"/>
</MX: formitem>
</MX: Form>
</MX: module>