2 Replies Latest reply on Mar 22, 2008 7:22 PM by ManOfNumenor

    Loading Legacy Flash 8 Content in a Flex 2.0.1 App

    ManOfNumenor Level 1
      Rewriting all legacy content in AS3 is a difficult business case to make. But, if we can load legacy swf (flash 8 swf) we can make the case of doing new content in AS3 and keeping old content in AS2. This is what I have been attempting to do, but I've run into a big snag.

      I'm having trouble using LocalConnection Flex project to communicate with a Flash8/AS2 swf.

      I wanted to use LocalConnection to pass strings back and forth (as described by Jesse Warden here: Controlling Flash Player 8 SWFs in Flash Player 9 SWFs NOTE: this link appears to be down, you may be able to recover it from Google's Cache).

      When I use this code:

      loadr= new SWFLoader();
      loadr.height = 600;
      loadr.width = 800;
      loadr.y = 150;
      loadr.x = 0;
      loadr.source = "TestingConnection.swf";
      loadr.addEventListener(Event.COMPLETE,LoadrCompleteEvent);

      I'm able to load the legacy (flash8) swf into my flex application. There are no domain problems here.

      But my attempts at using LocalConnection are not paying off. I get an error message (Error #2082: Connect failed because the object is already connected).

      Here's my code for the AS3 side of the connection (from Flex):

      import flash.net.LocalConnection;

      public class AS3ToAS2Com
      {
      private var aS3SendMessage:LocalConnection;
      private var aS2ReceiveMessage:LocalConnection;
      public function AS3ToAS2Com():void
      {
      aS3SendMessage = new LocalConnection();
      aS2ReceiveMessage = new LocalConnection();
      aS2ReceiveMessage.connect("aS2ToAS3Con");
      }
      public function AS2Message(msg:String):void
      {
      trace("AS2Message: "+ msg);
      SendAS3Message("test");
      }
      public function SendAS3Message(msg:String):void
      {
      aS3SendMessage.send("LegacyReceiveCon","AS3Message",[msg]);
      }
      }

      And here's the code in the AS2 class I use in the Flash CS3 fla:

      class FlashNineConnection
      {
      private var aS2SendMessage:LocalConnection;
      private var aS3ReceiveMessage:LocalConnection;
      function FlashNineConnection()
      {
      aS3ReceiveMessage = new LocalConnection();
      aS3ReceiveMessage.connect("LegacyReceiveCon");
      aS2SendMessage = new LocalConnection();
      }
      function AS3Message(msg:String)
      {
      trace("Flash 8/AS2 receiving this from Flex/as3");
      trace(msg);
      }
      function SendAS2MsgToAS3(msg:String)
      {
      trace("Flash8/AS2 is sending a message to Flex/AS3");
      aS2SendMessage.send("aS2ToAS3Con","AS2Message",[msg]);
      }
      }

      Here's the code from the Flash CS3 fla:

      import FlashNineConnection;
      var ffCon:FlashNineConnection = new FlashNineConnection();
      var timer:Number;
      timer = setInterval(GetValues,10);
      function GetValues()
      {
      if (ffCon.messages != Information_txt.text)
      {
      History_txt.text = History_txt.text + ffCon.messages;
      Information_txt.text = ffCon.messages;
      }
      }
      ffCon.SendAS2MsgToAS3("AS2 trying to talk to AS3 movie");
      send_btn.onRelease = function()
      {
      ffCon.SendAS2MsgToAS3("Info: " + Input_txt.text);
      }


      Does anyone have any tips or advice?

      William Chadwick

      Disclaimer: Of course the code above is not pretty (for example no try/catch blocks, etc)- to conserve space I took out lots of goodness.

      Background:

      Adobe's Flex Language reference on LocalConnection: http://livedocs.adobe.com/flex/201/langref/flash/net/LocalConnection.html

      Adobe AS2 LocalConnection Language Reference: http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveD ocs_Parts&file=00002338.html

      Adobe has an article about it here: http://kb.adobe.com/selfservice/viewContent.do?externalId=749eaa47&sliceId=1

      Jesse Warden here: Controlling Flash Player 8 SWFs in Flash Player 9 SWFs

      Igor Costa has a fantastic example (very clear- even though I cannot read the Spanish comments - I think it's Spanish): http://www.igorcosta.org/?p=18

      Another excellent link is this one: http://groups.google.com/group/flex_india/msg/85ec872c7d94851a

      This is interesting: AVM2 (AS3) to AVM1 (AS2/AS1) Communication via LocalConnection Cannot">http://www.senocular.com/pub/kirupa/as3tips_p7.html[L=Cannot load the SWFLoader content in a movieclip