0 Replies Latest reply on Apr 18, 2015 11:10 AM by juszczec2

    problem with javascript & swf communication

    juszczec2

      Well here's a problem.

      I've got a website with large javascript backend. This backend talks to a server over a socket with a socket bridge using http://blog.deconcept.com/swfobject/

      The socket "bridge" is a Flex/Flash .swf application/executable/plugin/thing for which the source is missing.

      I've got to change it.

      More facts:

      file appExePluginThing.swf 
      appExePluginThing
      .swf Macromedia Flash data (compressed), version 9

      I've used https://www.free-decompiler.com/flash/ to decompile the .swf file and I think I've sorted out what's the original code vs the libraries and things Flash/Flex built into it.

      I've used FDT (the free version) to rebuild the decompiled code into MYappExePluginThing.swf so I can run it with the javascript code and see what happens.

      I'm here because what happens isn't good. Basically, my javascript code (MYjavascript.js) gets to the point where it does

      window.log("init()");

      var so = new SWFObject("flash/MYappExePluginThing.swf"", socketObjectId, "0", "0", "9", "#FFFFFF");

      window.log("init() created MYappExecPluginThing!!!");

      so.addParam("allowScriptAccess", "always"); log("init() added Param!!");

      so.write(elId);

      log("init() wrote!");

      IE9's console (yeah, you read that right) shows

      init()

      created MYappExecPluginThing!!!

      init() added Param!!

      init() wrote!

      but none of the debugging i've got in MYappExePluginThing.as displays and nothing else happens.

      I'm trying to figure out what I've screwed up/what's going on? Is MYappExePluginThing.as running? Is it waiting on something? Did it fail? Why aren't the log messages in MYappExePluginThing.as showing up?

      The first most obvious thing is I'm using FDT which, I suspect, was not used to build the original. Is there some kind of magic "build javascript accessible swf thing" in FlashBuilder or some other IDE?

      First noteworthy thing I find is:

      file MYappExePluginThing.swf

      MYappExePluginThing.swf  Macromedia Flash data (compressed), version 14

      I'm using Flex 4.6 which, for all I know, may have a completely different mechanism for allowing javascript communication than was used in appExePluginThing.swf

      Does anyone know if that's true?

      For example, when FDT runs this thing (I can compile but FDT does not create a .swf unless i run it) I get a warning in the following method:

      private function init() : void {


      Log.log("console.log", "MYappExePluginThing init()");


      //var initCallback:String = Application.application.parameters.initCallback?Application.application.parameters.initCallback:"MYjavascript.MYappExePluginThing_init";

      var initCallback:String = FlexGlobals.topLevelApplication.parameters.initCallback?FlexGlobals.topLevelApplication.parameters.initCallback:"MYjavascript.MYappExePluginThing_init";


      try {

      ExternalInterface.addCallback("method1Callback",method1);

      ExternalInterface.addCallback("method2Callback",method2);

      ExternalInterface.call(initCallback);

      }

      catch(err:Error) {

      Log.log("console.log", "MYappExePluginThing init() ERROR err="+err);

      }

      }

      I got a warning that Application.application was deprecated and I should change:

         var initCallback:String =

      Application.application.parameters.initCallback?Application.application.parameters.initCallback:"MYjavascript.MYappExePluginThing_init";

      to:

      var initCallback:String =

      FlexGlobals.topLevelApplication.parameters.initCallback?FlexGlobals.topLevelApplication.parameters.initCallback:"MYjavascript.MYappExePluginThing_init";

      which I did but which had no effect on making the thing work.

      (Log.log() is something I added:

      public class Log{ 


      public static function log(dest:String, mssg:String):void{


      if(ExternalInterface.available){


      try{

      ExternalInterface.call(dest, mssg);

      }

      catch(se:SecurityError){ }

      catch(e:Error){ }


      }


      trace(mssg);  


      }

      )

      Additionally, in MYjavascript.js MYappExePluginThing_init looks like this:

      this.MYappExePluginThing_init = function () { log("MYjavascript.js - MYappExePluginThing_init:"); };

      Its supposed to be executed when MYappExePluginThing finishes initializing itself.

      Except its not. The message is NOT displaying on the console.

      Unfortunately, I cannot find any references explaining how you allow javascript communication in Flex 4.6 so I can check if I've got this structured correctly.

      Is it a built in kind of thing all Flex/Flash apps can do? Is my swf getting accessed? Is it having some kind of error? Is it unable to communicate back to my javascript?

      Does anyone have any links to references?

      If this was YOUR problem, what would you do next?