views:

2761

answers:

3

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).

+3  A: 

Answering my own question: https://sourceforge.net/forum/message.php?msg_id=5929756

  1. Export a method from your Flash file
  2. Invoke this method when the page finishes loading
  3. If the method returns anything except true then you can safely assume that the Flash file failed to load, though the underlying reason remains a mystery.
Gili
brilliant! This would help a lot today :D
Fahim Akhter
+2  A: 

Actually, when the HTML page finishes loading, the Flash content may not be completely loaded yet. If the SWF isn't done loading, then it will appear to have failed.

The method I usually recommend is to have the SWF call a JavaScript function through ExternalInterface right away when the document class constructor is invoked. Basically, assume that the SWF has failed to load unless that JS function is called.

joshtynjala
Fair enough, but I need a more concrete way to detect if a failure has occurred. A timeout is not reliable enough.
Gili
One problem with this method is that you can't have two instances of the flash on the same page. Or at least you don't know which-one has triggered the callback.
zimbatm
To tell which SWF triggered the callback, you can pass in a unique string or number as an identifier using FlashVars. When the SWF makes the call to JavaScript, it also passes the identifier in the arguments.
joshtynjala
A: 

Acording to adobe ExternalInterface documentation: http://livedocs.adobe.com/flex/3/langref/flash/external/ExternalInterface.html some web browsers restrict calling a Javascript function through ExternalInterface in the document class constructor if a pop-blocker is enabled.

Are there any other solution to detect when the swf movie has been successfully loaded?

gustavogb