1 Reply Latest reply on Apr 24, 2011 1:17 PM by kglad

    External Interface/Javascript call working in IE/Safari not FF/Chrome

    MartyGoldberg

      I'm hitting a brick wall here, and it's driving me mad.  Used to use ExternalInterface to call Flash functions from Javascript all the time, and now under CS5 (and the way it uses object id's instead of embed in html) it's stopped working for me in certain browsers.

       

      I put together a really simple program that has the person click a link in the browser that activates a javascript function that simply sends some text in to Flash to display in a TextArea.  Here's the as3 code:

       

      package  {

      import flash.display.*;

      import flash.external.ExternalInterface;

      import flash.net.*;

      import flash.events.*;

      import fl.controls.TextArea;

      import flash.text.TextField;

       

      public class sendtest extends Sprite {

      private var resultText:TextField = new TextField();

       

      public function sendtest() {

           addChild(resultText);

           resultText.x = 0;

           resultText.y = 0;

           resultText.text = "hello";

           flash.external.ExternalInterface.addCallback("putText", addText);

      }


       

      public function addText(theText:String):void

      {

           resultText.text = theText;

      }


      }

      }

       

       

       

      Here's the html page code:

       

       

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

      <head>

      <title>sendtest</title>

      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

      <style type="text/css" media="screen">

      html, body { height:100%; background-color: #000000;}

      body { margin:0; padding:0; overflow:hidden; }

      #flashContent { width:100%; height:100%; }

      </style>

      <script language="javascript">

       

           function putNewText()

           {

                var flash = document.getElementById('sendtest');

                flash.putText('thetext');

       

       

           }

      </script>

      </head>

      <body>

      <A href="javascript:putNewText()">test 1 2 3 </a><br>

      <div id="flashContent">

      <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100" height="100" id="sendtest" align="middle">

      <param name="movie" value="sendtest.swf" />

      <param name="quality" value="high" />

      <param name="bgcolor" value="#ffffff" />

      <param name="play" value="true" />

      <param name="loop" value="true" />

      <param name="wmode" value="window" />

      <param name="scale" value="showall" />

      <param name="menu" value="true" />

      <param name="devicefont" value="false" />

      <param name="salign" value="" />

      <param name="id" value="sendtest">

      <param name="allowScriptAccess" value="sameDomain" />

      <!--[if !IE]>-->

      <object type="application/x-shockwave-flash" data="sendtest.swf" width="100" height="100">

      <param name="movie" value="sendtest.swf" />

      <param name="id" value="sendtest">

      <param name="quality" value="high" />

      <param name="bgcolor" value="#ffffff" />

      <param name="play" value="true" />

      <param name="loop" value="true" />

      <param name="wmode" value="window" />

      <param name="scale" value="showall" />

      <param name="menu" value="true" />

      <param name="devicefont" value="false" />

      <param name="salign" value="" />

      <param name="allowScriptAccess" value="sameDomain" />

       

      <!--<![endif]-->

      <a href="http://www.adobe.com/go/getflash">

      <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />

      </a>

      <!--[if !IE]>-->

      </object>

      <!--<![endif]-->

      </object>

      </div>

      </body>

      </html>

       

       

       

      This works perfectly fine in IE and Safari, and the text "thetext" is sent to the Flash movie and displayed inside.  It causes errors in FF and Chrome however:
      Chrome: Uncaught TypeError: Object #<HTMLObjectElement> has no method 'putText'
      FF: flash.putText is not a function
      As for browser versions I'm using:
      FF is 4.0
      Chrome is 10.0.648.205
      IE is 8
      Safari on the Mac is 5.0.4
      Can anybody shed some light on what's going on here and offer a solution?  It shouldn't be this hard to access Flash movie functions in all 4 browsers.