|
Accueil - Identifying a debug or release SWF file at runtime
Created :
Last modified : Identifying a debug or release SWF file at runtime![]() It may be interesting to know at runtime whether an application is running from a debug or release SWF file. It allows the application to automatically execute debug specific code when the file is a debug SWF file and ignore this code when it is published as a release file. I can't find any property that indicates whether an application is running from a debug or release SWF file in the Flash Player API reference while searching for it the other day. I hope this solution will help. There's probably another way to achieve this, but I like this one because it can be written in one line only : isDebug = new Error().getStackTrace().search(/:[0-9]+]$/m) > -1; This code simply searches for line numbers of errors in StackTrace result. Only StackTrace result of a debug SWF file contains line numbers. Then we know that we are running a debug or release SWF file. Note that usually, I prefer and encourage to manually create an Ant task that will build a release SWF file with no debug info at all into it. But when working on little projects, you haven't time to create such an Ant file nor specific debug classes or files. You can also use something like I've tested this solution when the SWF file containing the code is loaded by another SWF file. It continues to work correctly independently from the host application. You can download an example that simply detects if the application is executed from a debug or release SWF file and write it on the screen. You can also download download another example which shows it all works the same when the release and debug SWF files are loaded into another application. CommentsHi Mike, Many developers and users have the debugger version of the player installed in their browser. You cannot rely on it to run an application in debug or release mode in a production environment. What I’m talking about here, is to identify if the SWF file itself was build for debugging or release. It’s something really safe and practical to use. I just made a feature request to have a native property in the Flash player API: I specifically ask for something like : flash.display.LoaderInfo.hasDebugInfo Please vote for it if you’re interested in. Thibault Imbert from www.bytearray.org just tell me that someone had the same idea in the past : http://michaelvandaniker.com/blog/2008/11/25/how-to-check-debug-swf/ I do not want to forget real initiators of this good idea, so this is done. Woah! You did it in a single line of code. Great idea! Hi Michael, glad to see that you well had my message on your own blog. As we are used to say in French when two people have the same good idea without knowing them each other : “les grands esprits se rencontrent”, translate it with : “great minds think alike”. Do you add : e.getStackTrace() != null because you have some cases where it was null ? I’ve checked in debug and release version of the player and it always return a non null String. Leave a comment |
||
| wordpress rss rss français rss english xhtml 1.1 css 2.0 wdg |
[…] This post was Twitted by amw7 […]