views:

118

answers:

2

I once accidentally uploaded only part of my flash program to my website (i.e., it was truncated), and to my biggest surprise, the flash object was loaded successfully into the webpage, no errors were raised, no warnings were given at all. (This was a release version of the player, the debug version might have behaved differently, I don't know.) Of course, it did not work properly, but still, the preloader screen was displayed correctly, and the download and initialization appeared to be finished normally.

My question is: is there a way to detect (either in actionscript/flash or in the embedding web page) when such a corrupted flash object has been loaded? Can I perhaps use the preloader to give a warning when this happens?

+1  A: 

There are a lot of ways to extract the header info from a SWF file (including its file size). Since this info is written at publishing time, it won't change if the file is truncated after uploading it. So, for instance, you can extract that info and check if the file size (according to the SWF header) == bytes loaded.

euge1979
Hmm, I wonder if this header info is accessible from within ActionScript...
David Hanak
Yeah it should be accessible - check this out (quite comprehensive example): http://www.senocular.com/flash/actionscript.php?file=ActionScript_3.0/com/senocular/utils/SWFReader.as
euge1979
Thanks, that's perfect!
David Hanak
+1  A: 

I don't know of any flash-specific ways, but it certainly wouldn't be difficult to write a script that compares the md5 hash of the original file with the version you have online. It would even be easy to set up in such a way that it automatically ran whenever the file was changed.

levand
I'd prefer a solution that worked on the client side.
David Hanak
The script could certainly reside on your client machine. Just write a program in any language that takes two parameters: the path to the local file and the url of the remote one. It then does an md5 of both and spits out the results. Just run the program every time you upload, and you're done.
levand