Problem accessing an external exponential method in Google Chrome

My Simple ActionScript I am trying to use Flash ExternalInterface to set up a callback so that JavaScript can call a method on my Flash object. Everything works fine in Safari, Firefox, and IE, but I can't get Chrome to work. When I try to execute the code in Chrome, I get the following error:

Uncaught TypeError: Object # <an HTMLObjectElement> does not have a 'SetText' method

Here is an example of the HTML I'm using (again, works fine in Safari, FF, and IE)

<html><body> <div id="mycontent"></div> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script> <script type="text/javascript"> swfobject.embedSWF("http://invincible.dynalias.com:8080/HelloWorld.swf", "mycontent", "400", "420", "9.0.0","expressInstall.swf", {}, {allowScriptAccess:'always'},{id:'hw',name:'hw'}); function getFlash(movieName) { return ( navigator.appName.indexOf("Microsoft") != -1) ? window[movieName] : document.getElementById(movieName); } </script><p> <input type="text" id="exampleText" /> <input type="button" value="Set Text" onclick="getFlash('hw').setText(document.getElementById('exampleText') .value)" /> </body> </html> 

and here is ActionScript ...

 package { import flash.display.Sprite; import flash.text.TextField; import flash.external.ExternalInterface; import flash.system.Security; public class HelloWorld extends Sprite { private var textField:TextField = new TextField(); public function HelloWorld() { Security.allowDomain("*"); ExternalInterface.addCallback("setText", this.setText); textField.text = "Hello, world!"; addChild(textField); } public function setText(text:String):void { this.textField.text = text; } } } 
+6
javascript google-chrome flash externalinterface
source share
5 answers

I have the same problem to trigger and receive listening events between javascript and flash.

The solution was to use the AC_OETags.js file from Adobe as an embedd script instead of a jQuery flash. (It is found in the zip file under the control of Client Side, Adobe may have other places)

A race condition issue when a flash drive creates javascript callbacks in a browser. For some reason, this is not properly handled by direct embedding.

 <div> <script> // Major version of Flash required var requiredMajorVersion = 10; // Minor version of Flash required var requiredMinorVersion = 0; var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision); AC_FL_RunContent( "src", "tagflash", "width", "200", "height", "200", "id", "myTagFlash", "quality", "high", "bgcolor", "#FFFFFF", "name", "myTagFlash", "allowScriptAccess","always", "type", "application/x-shockwave-flash", "pluginspage", "http://www.adobe.com/go/getflashplayer", "flashvars", "templateData=theYear:2010&theTagNumber:123" ); </script> </div> 

Then you can do: (works in IE, FF, Safari, Crome, ++)

 $("#tagFlash").gotoNewFrame(); 
+3
source share

I agree with Robson that this is a race condition, but it’s not about “writing a flash tag”, and adding a timer is not a good solution - it’s actually very dangerous.

The problem is that the SWF itself is not loaded and had the ability to initialize the external interface. For a small SWF in Chrome, the time may be more sensitive than other browsers, but the main problem is not typical for Chrome.

What you need to do is:

In ActionScript

Call this function from your constructor:

 public function InitializeExternalInterface():void { if (ExternalInterface.available) { // register actionscript functions so they can be called by JS ExternalInterface.addCallback("activate", activate); Security.allowDomain("www.example.com"); // send message to parent page that SWF is loaded and interface active trace("External Interface Initialized..."); ExternalInterface.call("flashInitialized") } else { trace("ERROR: External Interface COULD NOT BE Initialized..."); } } 

In your HTML

  <script> function flashInitialized() { alert("Initialized!"); // remove this obviously! $('#Main')[0].activate(); // safe to call Flash now } </script> 

You can find on your local machine that it works without this, but as soon as you add network delays to the equation, you will not regret not doing it. An arbitrary timer is a bad idea because you will still get an error when connecting slowly. This method allows the page to call the flash object as early as possible.


Note. Using the jQuery "ready" template does not solve the problem - although at first I took it for one.

 $(function() { $('#animation')[0].SetTitle("Hello"); } 

Also swfobject callbackFn also not a solution, because it simply tells you when the tag is inserted, and not when the SWF is loaded.

+13
source share

I was having problems with ExternalInterface and Firefox and Chrome, and I found that Adobe Script wasn’t writing the Flash shortcut fast enough, so when the browser tried to find the addCallback () function, it wasn’t there at that time.

Just putting the Javascript function that calls the Flash addCallback () created in the call to window.setTimeout () solves the problem. Delays of less than 200 ms still pose a problem.

I did not have to use a solution trying to find if the length attribute exists for the document [FlashId] object. Just calling "FlashEmbed = document [FlashId]" worked fine.

+3
source share

After long bits, I finally decided to use the official solution from Adobe:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html

Find ExternalInterfaceExample.as .

0
source share

The workaround for the problem can be disabled by disabling the built-in Chrome flash module:

  • type chrome: // plugins in the chrome address bar.
  • expand the details of the plugins by clicking the information in the upper right corner.
  • in the entry "Adobe Flash Player" by disabling the first.

This is not a solution, but shows why this is happening in Chrome. Chrome with built-in flash plugins, which often cause problems when we use ExternalInterface AS3, is annoying.

0
source share

All Articles