Skip to main content

How to send variables from on SWF flex file to another SWF file Using Flex.

How to Communicate From one SWF Flex file to another SWF Flex File ?

See the below example, This is loading external swf flex file into parent SWF File and sharing the data or variable from parent to child and child to parent.

Parent.mxml


CODE:
1:  <?xml version="1.0" encoding="utf-8"?>
2: <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%">
3: <mx:Script>
4: <![CDATA[
5: import mx.events.CloseEvent;
6: import mx.controls.SWFLoader;
7: import mx.managers.PopUpManager;
8: import mx.containers.TitleWindow;
9: import mx.controls.Alert;
10:
11: public var tw:SWFPlaceHolder;
12:
13: public function launchExternalSWF(title:String,swfFilePath:String):void{
14:
15: // setting a variable for child SWF File
16: Application.application.parameters.childVar=txt.text;
17:
18: tw = PopUpManager.createPopUp(this,SWFPlaceHolder,true) as SWFPlaceHolder;
19: tw.title = title;
20: tw.width=600;
21: tw.height=400;
22: tw.launchSWF(swfFilePath);
23: }
24:
25: public function getValueFromChildSWF():void{
26: // geting value from child SWF File
27: Alert.show(Application.application.parameters.parentVar,"Parent App");
28: }
29: ]]>
30: </mx:Script>
31: <mx:VBox width="100%" height="100%" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
32: <mx:HBox width="100%" horizontalAlign="center" verticalAlign="middle">
33: <mx:Label text="Set Value For Child SWF File " />
34: </mx:HBox>
35:
36: <mx:HBox width="100%" horizontalAlign="center" verticalAlign="middle">
37: <mx:TextArea id="txt" width="100%" height="200">
38: <mx:text>
39: Hello World for Child SWF.....
40: </mx:text>
41: </mx:TextArea>
42: </mx:HBox>
43: <mx:HBox width="100%" horizontalAlign="center" verticalAlign="middle">
44: <mx:Button label="Click to Lanuch External SWF File" id="btn" click="{this.launchExternalSWF('Launch Child SWF File','ExternalSWF.swf')}" />
45: <mx:Button label="Get Value From Child SWF File" id="btn1" click="{this.getValueFromChildSWF()}" />
46: </mx:HBox>
47: </mx:VBox>
48: </mx:Application>
49:



Here is another File for loading swf file SWFFilePlaceHolder.mxml


CODE:
1:  <?xml version="1.0" encoding="utf-8"?>
2: <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="500" height="500" creationComplete="{PopUpManager.centerPopUp(this)}" showCloseButton="true" close="{PopUpManager.removePopUp(this)}">
3: <mx:Script>
4: <![CDATA[
5: import mx.events.CloseEvent;
6: import mx.managers.PopUpManager;
7: import mx.controls.Alert;
8:
9: public function launchSWF(path:String):void{
10: swf.source = path;
11: this.addEventListener(CloseEvent.CLOSE,swfUnload);
12:
13: }
14:
15: public function swfUnload(evt:Event):void{
16: swf.source = null;
17: }
18: ]]>
19: </mx:Script>
20: <mx:SWFLoader id="swf" width="100%" height="100%" />
21: </mx:TitleWindow>
22:


This is The Child or External SWF Flex File Child.mxml

CODE:
1:  <?xml version="1.0" encoding="utf-8"?>
2: <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="White">
3: <mx:Script>
4: <![CDATA[
5: import mx.controls.Alert;
6: public function getValueFromParentSWF():void{
7: Alert.show("Parent App Value:\n"+ Application.application.parameters.childVar,"Child SWF");
8: this.setValueForInternalSWF();
9: }
10:
11: public function setValueForInternalSWF():void{
12: Application.application.parameters.parentVar = txt.text;
13: }
14: ]]>
15: </mx:Script>
16: <mx:Panel label="Child App" width="100%" height="100%">
17: <mx:VBox width="100%" height="100%">
18: <mx:HBox width="100%" horizontalAlign="center" verticalAlign="middle">
19: <mx:Label text="Set Value For Parent SWF File " />
20: </mx:HBox>
21: <mx:HBox width="100%" horizontalAlign="center" verticalAlign="middle">
22: <mx:TextArea id="txt" width="100%" height="200" keyDown="setValueForInternalSWF()">
23: <mx:text>
24: Hello World for Parent SWF.....
25: </mx:text>
26: </mx:TextArea>
27: </mx:HBox>
28: <mx:HBox width="100%" horizontalAlign="center" verticalAlign="middle">
29: <mx:Button label="Click To Get Value From Parent App Textarea" click="getValueFromParentSWF()" />
30: </mx:HBox>
31: </mx:VBox>
32:
33: </mx:Panel>
34: </mx:Application>
35:

Comments

Post a Comment

Popular posts from this blog

Flex Interview Questions

1) What is Flex? Flex is used to devleop Rich Internet Application (RIA) You can both desktop & web based applicaiton.It is markup language and object-oriented languages its many syntax match with flash action script. Flex Developers use typically five distinct phases to develoep Rich Internet Application. Design Configure Build Deploy Secure 2) How do i get Page URL and Query String ? We can use mx.core.Application.application.url (mx.core)package to work with current page URL. & query string. 3) Describe flex component file types ? There are following file types we can use in flex. extension .mxml - a component implemented as an MXML file. extension .as - a component implemented as an ActionScript class. extension .swc - a SWC file contains components in a packge. 4) Difference between target & currentTarget ? target : This property is set by the dispatchEvent() method. You cannot change this to a different object. currentTarget : This property is set by component instan...

Free Online Meta Tag Creator

Meta Tags are HTML header part tags, which describe about the website . These meta tags provide information to the search engines such as Google, Yahoo, MSN Search, AOL Search, AltaVista ,HotBot, Lycos, Excite and other search engines . It is very important to the search engine point of view meta tags must be well formed and meaningful . HTML Meta tags help to increase your website rank. The common questions arise for meta tags are as follows? What Are META Tags? META Tags are HTML header part tags of HTML Document that provide internal & external information about the content of a web page or website while you are browsing that page you are not able to see that Meta tags on your browser output. How META Tags Work for Search Engine? Meta tag tell to search about the page such as keywords, Description, Content Language etc, which parameter you put in contents attribute of the meta tags that's is read by search engine to index your page with accuracy, which is totally depend to...