The "modern" updated way to embed a flash object, according to Adobe:
<object id="theFlash" name="theFlash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
width="400" height="225" align="middle">
<param name="movie" value="theflashfile.swf" />
<param name="allowScriptAccess" value="always" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash"
data="getStreamFrame.swf" width="400" height="225">
<param name="allowScriptAccess" value="always" />
<!--<![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>
When trying to call an AS3 function in the SWF, from Javascript:
var flashObj = document.getElementById('theFlash');
flashObj.someASFunction();
(and on the AS side:)
import flash.external.*;
function someASFunction() {
//show some text
}
ExternalInterface.addCallback("someASFunction", someASFunction);
This doesn't work in Firefox and Chrome. The flash works and loads. flashObj does get a reference to the object, but someASFunction is undefined and doesn't get called.
If I replace the object tag with an embed tag:
<embed id="theFlash" name="theFlash" height="225" width="400" align="middle"
type="application/x-shockwave-flash" allowscriptaccess="always"
src="theflashfile.swf" />
Then it works on Firefox and Chrome (the AS function is called and works properly) - (it doesn't work in IE though).
How come it doesn't work with an object tag?
How "safe" it is to use the embed tag instead of the object tag? Is it not obsolete?
Note, that it is definitely not a timing issue - If I call the AS function from JS from an onclick function - then the results are the same.
When using the recommended Adobe method, I also failed to target the flashmovie in FF and Chrome. I ended up using the following code and ExternalInterface works just fine in all browsers
<div id="flashContent">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="619" height="99" id="myFlashMovie" align="middle">
<param name="movie" value="myFlashMovie.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#f2f2f2" />
<param name="allowScriptAccess" value="sameDomain" />
<!--[if !IE]>-->
<embed src="myFlashMovie.swf" quality="high" bgcolor="#f2f2f2"
width="619" height="99" name="myFlashMovie" align="middle"
play="true" loop="true" quality="high" allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
<!--<![endif]-->
</object>
For targeting the flash movie, I use this java script
function sendDataToFlash(data) {
getFlashMovie("myFlashMovie").myCallbackInFlash(data);
}
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
if(isIE) return window[movieName];
else return document[movieName];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With