Communication with module in flex4 Application

Source: Internet
Author: User

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 >

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.