2 Replies Latest reply on Feb 17, 2008 7:24 AM by peterent

    AS2 swf to AS3 local Connection

    miragevideo
      Hello:
      I am embedding multiple copies of a single AS2 swf build in FLASH into a FLEX2 AS3 swf. I am using LocalConnection to communicate from FLEX to the flash swfs. This exhibits the strange behaviour that only the last loaded swf actually works correctly. The swf is a told to gotoAndStop at a particular frame. I trace the FLASH swf function and it is getting the correct frame number from FLEX. But it does not work correctly.

      see a samle at http://www.miragevideo.com/test.html .

      The problem seems to be the localConnectin being shared by three similar instances of the gauge class. Any ideas??

      Here is the FLEX code
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="200" horizontalScrollPolicy="off" verticalScrollPolicy="off">
      <mx:Image id="gaugeSWF" source="@Embed(source='../../resources/gauge.swf')" creationComplete="init();" />
      <mx:Script>
      <![CDATA[

      import flash.net.LocalConnection;
      private var toFlash_lc:LocalConnection = new LocalConnection();
      private var _amount:int;

      private function init():void{
      toFlash_lc.addEventListener(StatusEvent.STATUS, onStatus);
      toFlash_lc.send("lc_from_Flex", 'setGauge',_amount) ;
      }

      public function set amount(val:int):void{
      _amount = val;
      }


      private function onStatus(event:StatusEvent):void {
      switch (event.level) {
      case "status":
      // trace("LocalConnection.send() succeeded");
      break;
      case "error":
      trace("LocalConnection.send() failed");
      break;
      }
      }

      ]]>
      </mx:Script>
      </mx:Canvas>

      and the FLASH code:
      // Code in the receiving SWF file
      var receiving_lc:LocalConnection = new LocalConnection();
      receiving_lc.setGauge = function(frame:Number) {
      trace("in flash frame= " + frame + " angle: " + ((frame/100)*180));
      mask._rotation = -(frame/100)*180;
      angle.text = frame.toString();
      };
      receiving_lc.connect("lc_from_Flex");


      stop();