6 Replies Latest reply on Jul 24, 2008 8:03 AM by kglad

    Flash to JS using ExternalInterface

    choxxo
      In principle I'm not stupid... or at least that's what I used to think. But, after spending more than 2 days trying to do what seems to be relatively straigtforward and getting nowhere, I'm beginning to have my doubts. :scared:

      All I am trying to do is use flash mc buttons to send javascript into action in a bog-standard website.

      1. Click on mc_button in the flash menu --- send instruction to operate menu function in the Javascript code

      2. JS code receives the call and the argument telling it to select a piece of text to display in a div with a specific id.

      This is not rocket science.... but it doesn't work for me.

      The actionscript code in frame 1 of the timeline: The mc_button has an instance name of 'm1'
      import flash.external.*;

      _root.m1.onRelease=function(){
      var callJasFunction:String="menuGo";
      var txt:String="menu 1 choices";
      ExternalInterface.call(callJasFunction,txt);
      }


      This code with variation is repeated for the other menu mc instances.

      I publish the movie using the recommended sttings and insert the javascrip`t function into the space provided in the generated script, which then looks like:

      <script language="JavaScript">
      <!--
      var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
      // Handle all the FSCommand messages in a Flash movie.
      function menu_test_DoFSCommand(command, args) {
      var menu_testObj = isInternetExplorer ? document.all.menu_test : document.menu_test;
      //

      function menuGo(){ // this is just to test that the call is working - it isn't
      alert(txt);
      }
      //
      }
      // Hook for Internet Explorer.
      if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
      document.write('<script language=\"VBScript\"\>\n');
      document.write('On Error Resume Next\n');
      document.write('Sub menu_test_FSCommand(ByVal command, ByVal args)\n');
      document.write(' Call menu_test_DoFSCommand(command, args)\n');
      document.write('End Sub\n');
      document.write('</script\>\n');
      }
      //-->
      </script>

      Can anyone shed light on where I am going wrong?

      Cheers

      Charco