Communication between flex and SwF created by Flex

Source: Internet
Author: User

This is found onlineCode.

 

Load the FLEX of the sub-SwFProgramCode

<? XML version = "1.0" ?>
< MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml" Layout = "Absolute" >

< MX: script >
<! [CDATA [

Import MX. Managers. systemmanager;
Import MX. Controls. label;

[Bindable]
Public var loadedswf: systemmanager;

Private function initnestedappprops (): void {
Loadedswf = systemmanager (myloader. content );
}

Public Function updatelabel (): void {
LBL. Text = loadedswf. application ["text_1"]. text;
}

// Write to the label control in the loaded application.
Public Function updatenestedlabels (): void {
Loadedswf. application ["text_2"]. Text = text_value.text;
}
]>
</ MX: script >

< MX: Label ID = "LBL" X = "204" Y = "69" Fontsize = "12" />
< MX: swfloader ID = "Myloader" Width = "250" Height = "200"
Source = "Subswf.swf"
Creationcomplete = "Initnestedappprops ();" X = "13" Y = "124" />

< MX: button Label = "Get the control value for loading SWF"
Click = "Updatelabel ();" Fontsize = "12" X = "10" Y = "65" />
< MX: button Label = "Modify the control value for loading SWF"
Click = "Updatenestedlabels ();" Fontsize = "12" X = "10" Y = "33" />
< MX: textinput ID = "Text_value" X = "192" Y = "35" Fontsize = "12" />

</ MX: Application >

 

 

 

Sub-SwF program code 

<? XML version = "1.0" encoding = "UTF-8" ?>
< MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml" Layout = "Absolute" >
< MX: Panel X = "0" Y = "0" Width = "250" Height = "200" Layout = "Absolute" Title = "Loaded SWF file" Fontsize = "12" >
< MX: textinput ID = "Text_1" X = "10" Y = "41" Fontsize = "12" Text = "Hello everyone, I'm flex" />
< MX: textinput ID = "Text_2" X = "10" Y = "88" Fontsize = "12" />
</ MX: Panel >
</ MX: Application >

 

 

If you need to call the sub-SwF method, you can convert the loadswf application to an object, and then call the method in the sub-SWF. Otherwise, the method cannot be found.

 VaRLoadswf: systemmanager=Systemmanager (myloader. content );

(Loadswf. Application as object). Test ();

 

Source code download

 

#===================================================== ==========================================================

Later, I found that the above Code is still risky. If the SWF file to be loaded is large, the value of application in item_loadswf may be null.

Below is a piece of code I added.

Supplemental code Private VaR _ Loadswf: systemmanager;
Private VaR Content: image;
Private Function Onloadcompleted (Event: Event ): Void
{
_ Loadswf = systemmanager (content. content);
_ loadswf. addeventlistener (flexevent. application_complete, swfready);

function swfready (Event: flexevent): void
{< br> _ loadswf. removeeventlistener (flexevent. application_complete, swfready);
(_ loadswf. application as object ). test ();
}< BR >}

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.