NOTE: I have since discovered the Capabilities class that has a boolean called isDebugger. Therefore you can do this like so:

if (Capabilities.isDebugger)
{
trace('This app is running in the ADL');
}

Original post:

I recently came across the situation where I wanted to detect if my AIR application was running, “for real” or running in debug mode (in the Adobe Debug Launcher ADL).

With a standard Flex > SWF project you can change the HTML of the debug template to pass through a debug=true variable. However with an AIR project you don’t have this luxury.

The reason I want to do this, is I don’t want some things to happen when I’m debugging (such as sending stats to the server) and I don’t want to have custom variables or comment out code incase I forget to turn them back on before pushing live. By having a way of checking if the app is running in the ADL you can optionally stop things, safe in the knowledge that when they go live they will work.

I searched the web to see if there was a way to tell if AIR was running in debug mode, or in the ADL or was even a release build, but I couldn’t find a specific API call. What I did find is a number of methods that only worked if running in the ADL. All I had to do then was find one that returned different values depending on that fact. The Error class has a method getStackTrace() that return null if not running in the ADL and a string if it is, this was perfect and can be used like so:

if (new Error().getStackTrace() != null)
{
trace('This app is running in the ADL');
}

This code isn’t perfect, in the future the getStackTrace method could start working when not running in the ADL. You could also combine a few ADL specific methods, for better piece of mind. If you know of a better solution please let me know!

This entry was posted on Tuesday, July 7th, 2009 at 3:39 pm and is filed under AIR, ActionScript, Development, Flex, Technology. You can leave a comment and follow any responses to this entry through the RSS 2.0 feed.

Leave a Reply