3 Replies Latest reply on Sep 8, 2010 9:27 AM by Flex harUI

    SWFLoader Bugs?!!!!!!!!!!!!!

    Yue_Hong Level 1

      I am trying to do the communication betwen Flex with Flash (SWF) loaded by SWFLoader. However, I always encounter the problem that sometimes the program do run properly, but sometime it doesn't even start up.

       

      Here is my Flex code:

      <?xml version="1.0" encoding="utf-8"?>
      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                  xmlns:s="library://ns.adobe.com/flex/spark" 
                                  xmlns:mx="library://ns.adobe.com/flex/mx">
           <s:layout>
                <s:VerticalLayout/>
           </s:layout>
           <fx:Script>
                <![CDATA[
                     [Bindable]
                     protected var flashSaid:String = "";
                     protected var mySwfMc:MovieClip;
      
                     protected function setSwfMc():void{
                          mySWFLoader.content['myFlexParent'] = this;
                          mySwfMc = mySWFLoader.content as MovieClip;
                     }
                     
                     public function listenToFlash(stringToShow:String):void{
                          flashSaid = stringToShow;
                     }
                     
                     protected function talkToFlash(stringToPass:String):void{
                          mySwfMc.listenToFlex(stringToPass);
                     }
                     
                ]]>
           </fx:Script>
           <fx:Declarations>
                <!-- Place non-visual elements (e.g., services, value objects) here -->
           </fx:Declarations>
           <mx:SWFLoader id="mySWFLoader" source="talk.swf" complete="setSwfMc()"/>
           <s:Button label="sendtoFlash" click="talkToFlash('hehehhhe')"/>
           <s:Label id="distxt" text="{flashSaid}"/>
      
      
      </s:WindowedApplication>
      
      

       

       

      Here if my Flash Code (created using Flash CS3, setting: AS3, Flash Player 9):

      var myFlexParent:Object;
      var i:Number;
      function talkToFlex(me:MouseEvent):void{
           myFlexParent.listenToFlash("heheheheheeh");
      }
      
      function listenToFlex(stringToShow:String):void{
           flexSaidTxt.text = stringToShow; 
      }
      talkToFlexBtn.addEventListener(MouseEvent.CLICK,talkToFlex);
      

       

       

      I have tried to fixing and make the thing works for almost 2 days, but it didn't. The weird thing is that, I have tried to remove the script code, everything except the swfloader to load the swf file, the application window appears when I try to run the application, but the component inside it jumping up and down crazily.

       

      The console window shows me:

      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      [SWF] talk.swf - 2,684,356 bytes after decompression
      

       

      Do you know why is this happens? How can I solve it? Thanks.