0 Replies Latest reply on Nov 9, 2006 8:07 AM by gtuhl

    Problems with ExternalInterface

    gtuhl
      I am trying to have a Flex2 TitleWindow communicate with Javascript and then have that Javascript communicate back with the ActionScript in the TitleWindow.

      Calling Javascript from ActionScript is working perfectly, however, I have not yet been able to successfully call an ActionScript method from Javascript.

      My setup is fairly involved, but here are the basic components. I would be happy to provide any additional information that could help.

      I have a creationComplete event in my TitleWindow which calls an initialization function that registered callbacks and then a callback function defined in the same TitleWindow.
      ---
      public function init():void {
      if (ExternalInterface.available){
      ExternalInterface.addCallback("testCallback", testCallback);
      Alert.show("Callbacks are registered");
      }
      else{
      Alert.show("ExternalInterface was not available");
      }
      }

      public function testCallback():void {
      Alert.show("Received callback from Javascript");
      }
      ---

      Then when the user clicks a button on the TitleWindow, I do the following:
      ---
      ExternalInterface.call("jsFunction", "foo", "bar");
      ---

      In my Javascript, I have the following:
      ---
      var jsFunction = function(string1, string2){
      alert("Received: " + string1 + ", " + string2);
      flexObject.testCallback();
      }
      ---

      In my Html, I have the following to imbed flex
      ---
      <object id='flexObject' codebase=' http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' height='100%' width='100%'>
      <param name='src' value='flexapp.swf'/>
      <param name="allowScriptAccess" value="always"/>
      <embed name='flexObject' src='flexapp.swf' allowScriptAccess='always' pluginspage=' http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' height='100%' width='100%'/>
      </object>
      ---

      Now, I can load the html page just fine and everything look great and is functional. When I go to the TitleWindow in question and click the button that calls the Javascript, it works perfectly and I see the Javascript alert box displaying "Receiving: foo, bar". However, I never get any response from the ActionScript callback that should be called at that point by the Javascript.

      Looking at it more closely, I have been able to determine that flexObject.testCallback is undefined at the point I try to call it in my Javascript. Javascript is unable to see that this method exists. If I try to use Firebug to trace the Javascript side of things, it crashes at the flexObject.testCallback line.

      I have tried doing:

      flexObject.testCallback();
      document.getElementById("flexObject").testCallback();
      testCallback();

      None of them work. Has anyone had luck with this? I have tried it with FireFox 2 and IE 6 with the same result.