My product opens a web browser and points it at an HTML file containing a local Flash application. How do I detect programmatically whether this file loaded successfully and if not what exception was thrown? Is there a way to do this using Javascript?
Checking externally whether the file exists on disk is not enough because I've seen other failures occur (race conditions might be involved).
Answering my own question: https://sourceforge.net/forum/message.php?msg_id=5929756
Here is an example:
Flash
var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
if (ExternalInterface.available)
{
var onLoaded:String = params["onLoaded"];
if (onLoaded != null)
ExternalInterface.call(onLoaded, true);
}
Javascript
var flashLoaded = false;
var flashTimer;
function onFlashLoaded()
{
flashLoaded = true;
clearTimeout(flashTimer);
}
function onFlashTimeout()
{
if (!isFlashLoaded)
{
// Remove the Flash object in case it is partially loaded
$("#videoFeed").empty();
$("#videoFeed").append('<div id="flashObject"></div>');
alert("Failed to load video player");
}
clearTimeout(flashTimer);
}
function connectToVideo()
{
var flashvars = {};
flashvars.onLoaded = "onFlashLoaded";
var params = {};
params.menu = false;
var attributes = {};
isFlashLoaded = false;
flashTimer = setTimeout("onFlashTimeout()", 5000);
swfobject.embedSWF("flash/VideoFeed.swf", "flashObject", "800", "600", "11", "expressInstall.swf", flashvars, params, attributes);
}
In cases where you cannot modify the swf and adding an ExternalInterface is not an option, you can still use Javascript to get the status of the swf. For example, you can call document.getElementById(swf_id).PercentLoaded() from Javascript, and wait for it to be 100.
That won't tell you what exception was thrown if the swf failed to load, but at least you will know for sure whether it loaded. Other useful calls are found here: http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_03.html
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