I launch an Actionscript function through javascript via ExternalInterface.
<script type="text/javascript">
var flashvars = {};
var params = {};
params.allowscriptaccess = "always";
var attributes = {};
swfobject.embedSWF("/img/tts_langx.swf", "tts_lang", "1", "1", "9.0.0", false, flashvars, params, attributes);
</script>
However, when flash doesn't load, or player isn't available, everything breaks. So I want to check for flash and if it is not loaded for some reason kill that part of the process only.
I make the check through:
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
and then I make:
if(thisMovie('myFlash').theActionscriptFunction==null){...}else{}
which is a very ugly way, but works in firefox and safari, not in Chrome.
How can i make this check in the best way and know for all the browsers, if flash is available for functions in it?
A very simple way would be to change the Flash movie in this manner:
When the movie loads (in the load listener in AS), add this
if(ExternalInterface.available) {
ExternalInterface.call(flashReady);
}
and in the javascript, have a function called flashReady which does the thing it needs to
function flashReady() {
//Your awesome function body here
}