I have been busy with project development in my company recently. I haven't written a blog for a while,
Some of them use flex4 in project development, so share one,
Communication with module in Application Take Logon As An Example
Ideas:
1. Write the interface iuserentry: Inherit ieventdispatcher, add it, set and return the username method name;
2. Create a module, implement the iuserentry interface, create a logon event, and issue a logon event binding;
3. Create and use interfaces and instances in the application;
MainCode:
// Iuserentry. AS Interface
Package com. oreilly. f4cb
{
Import flash. Events. ieventdispatcher;
Public interface iuserentry extends ieventdispatcher
{
Function getfullname (): string;
Function get firstname (): string;
Function set firstname (STR: string): void;
Function get lastname (): string;
Function set lastname (STR: string): void;
}
}
// Mymodule. mxml
< MX: Module Implements = "Com. oreilly. f4cb. iuserentry"
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 = "Vertical" Width = "100%" Height = "100%" >
< FX: Metadata >
[Event (name = "Submit", type = "flash. Events. Event")]
</ FX: Metadata >
< FX: script >
<! [CDATA [
Private VaR _ firstname: string;
Private VaR _ lastname: string;
Private function handlesubmit (): void
{
Firstname = firstnameinput. text;
Lastname = lastnameinput. text;
Dispatchevent (new event ("Submit "));
}
Public Function getfullname (): String
{
Return _ lastname + "," + _ firstname;
}
[Bindable]
Public Function get firstname (): String
{
Return _ firstname;
}
Public Function set firstname (value: string): void
{
_ Firstname = value;
}
[Bindable]
Public Function get lastname (): String
{
Return _ lastname;
}
Public Function set lastname (value: string): void
{
_ Lastname = value;
}
]>
</ FX: script >
< S: hgroup Verticalalign = "Bottom" >
< S: Label Text = "First name :" />
< S: textinput ID = "Firstnameinput" Width = "100%" />
</ S: hgroup >
< S: hgroup Verticalalign = "Bottom" >
< S: Label Text = "Last Name :" />
< S: textinput ID = "Lastnameinput" Width = "100%" />
</ S: hgroup >
< S: button Label = "Submit" Click = "Handlesubmit ();" />
</ MX: Module >
// Comunicationwithmodule. mxml
< 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" >
< FX: script >
<! [CDATA [
Import com. oreilly. f4cb. iuserentry;
Private var mymodule: iuserentry;
Private function handlemoduleready (): void
{
Mymodule = moduleloader. Child as iuserentry;
Mymodule. addeventlistener ("Submit", handlesubmit );
}
Private function handlesubmit (EVT: Event): void
{
Welcomefield. Text = "hello" + mymodule. getfullname ();
}
Public Function getinformation (): String
{
Return "Greetings! ";
}
]>
</ FX: script >