topical media & game development

talk show tell print

flex-component-loader.mx

flex-component-loader.mx [swf] flex


  <?xml version="1.0" encoding="utf-8"?>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" backgroundGradientColors="[#ffffff, #ffffff]" width="820" height="570">
          <mx:Script>
                  <![CDATA[
                          import flx.external.FlashInterface;
                          import flx.events.FlashInterfaceEvent;
                          import mx.controls.Alert;
  
                          [Embed(source="local/flex/assets/images/flex_icon.png")]
                          [Bindable]
                          public var logo:Class;
                          
                          private function init():void
                          {                                
                                  swf1.source = "local/flex/assets/flash/flash8.swf?flashId=flash_1";
                                  swf2.source = "local/flex/assets/flash/flash8.swf?flashId=flash_2";
                                  
                                  FlashInterface.publish(this, true); // FlashInterface.publish (required), makePublic param (optional)
                                  FlashInterface.addEventListener("talkToAll", talkToFlexHandler);
  
                                  //FlashInterface.register("flexText", textArea);
                                  //FlashInterface.unregister("flexText", textArea);
                          }
                          
                          private function dispatch():void
                          {
                                  FlashInterface.dispatchEvent({type:'talkToAll', data:"Dispatched from Flash9.\n\nFlashInterface.dispatchEvent({type:\'talkToAll\', data:\"Dispatched from Flash9.\"});"});                
                          }
                          
                          private function execMethod1():void
                          {
                                  FlashInterface.call("flash_1.sendMessage", "Method executed from Flash9.\n\nFlashInterface.call(\"flash_1.sendMessage\", \"Method executed from Flash9.\");");
                          }
  
                          private function execMethod2():void
                          {
                                  FlashInterface.call("flash_2.sendMessage", "Method executed from Flash9.\n\nFlashInterface.call(\"flash_2.sendMessage\", \"Method executed from Flash9.\");");
                          }
                          
                          private function execProp1():void
                          {
                                  FlashInterface.call("flash_1.txtOutput.text", "Property executed from Flash9.\n\nFlashInterface.call(\"flash_1.txtOutput.text\", \"Property executed from Flash9.\");");
                          }
  
                          private function execProp2():void
                          {
                                  FlashInterface.call("flash_2.txtOutput.text", "Property executed from Flash9.\n\nFlashInterface.call(\"flash_2.txtOutput.text\", \"Property executed from Flash9.\");");
                          }        
                          
                          private function talkToFlexHandler(evt:FlashInterfaceEvent):void
                          {
                                  textArea.text = evt.data;
                          }
                          
                          public function sendMessage(message:String):void
                          {
                                  textArea.text = message;
                          }
                  ]]>
          </mx:Script>
          <mx:Canvas cornerRadius="8" borderStyle="solid" left="5" top="5" right="5" height="560">
                  <mx:Canvas borderStyle="solid" cornerRadius="8" left="5" right="5" top="354" height="196">
                          <mx:Button x="10" y="36" label="Flash1 Call Method" click="execMethod1()"/>
                          <mx:Button x="149" y="36" label="Flash1 Set Property" click="execProp1()"/>
                          <mx:Button y="36" label="Dispatch Event" click="dispatch()" width="204" x="296"/>
                          <mx:Button x="508" y="36" label="Flash2 Call Method" click="execMethod2()"/>
                          <mx:Button x="647" y="36" label="Flash2 Set Property" click="execProp2()"/>
                          <mx:TextArea x="228" y="66" width="340" height="93" id="textArea"/>
                          <mx:Image y="88" width="48" height="48" source="{logo}" scaleContent="false" x="508" alpha=".2"/>
                          <mx:Button y="167" label="Clear" click="textArea.text=&quot;&quot;" width="80" x="488"/>
                          <mx:Label x="10" y="10" text="Flash 9 Control Panel" fontWeight="bold" fontStyle="italic" fontSize="16" fontFamily="Arial" color="#cc0000"/>
                  </mx:Canvas>
                  <mx:Label x="10" y="10" text="Flash 9 &amp; Flex 2 - Using AVM2" fontWeight="bold" fontStyle="italic" fontSize="16" fontFamily="Arial" color="#cc0000"/>
                  <mx:SWFLoader x="0" y="66" width="400" height="280" id="swf1" scaleContent="false"/>
                  <mx:SWFLoader x="408" y="66" width="400" height="280" id="swf2" scaleContent="false"/>
                  <mx:Label x="10" y="42" text="These two Flash 8 SWFs have been loaded inside a Flash 9 SWF. The Flash 9 SWF control panel is located underneath." fontSize="11"/>
                  <mx:Label x="763" y="10" text="v.2.0" fontWeight="bold" textAlign="right"/>
          </mx:Canvas>
  </mx:Application>
  


(C) Æliens 27/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.