Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I agree with Robson that it is a race condition, but it's not in 'writing the Flash tag' and adding a timer is not a good solution - in fact its very dangerous.</p> <p>The problem is that the SWF itself isn't loaded and had a chance to initialize your external interface. For a small SWF in Chrome the timing may be more sensitive than other browers, but the underlying problem isn't specific to Chrome.</p> <p>What you need to do is this :</p> <p><strong>In Actionscript</strong></p> <p>Call this function from your constructor :</p> <pre><code>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..."); } } </code></pre> <p><strong>In your HTML</strong></p> <pre><code> &lt;script&gt; function flashInitialized() { alert("Initialized!"); // remove this obviously! $('#Main')[0].activate(); // safe to call Flash now } &lt;/script&gt; </code></pre> <p>You may find on your local machine that it works without this, but as soon as you add network delays into the equation you'll regret not doing this. An arbitrary timer is a bad idea because you will still get the error on a slow connection. This method lets the page call the flash object at the earliest possible time.</p> <hr> <p><strong>Note:</strong> Using jQuery's 'on ready' pattern is NOT a solution to the problem - although at first I mistook it for one.</p> <pre><code>$(function() { $('#animation')[0].SetTitle("Hello"); } </code></pre> <p>Also swfobject's <a href="http://code.google.com/p/swfobject/wiki/api" rel="noreferrer"><code>callbackFn</code></a> is also not a solution becasue that just tells you when the tag is inserted and not when the SWF is loaded.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload