Use Capabilities.isDebugger to avoid the startAtLogin error in ADL

 

In DestroyTwitter, I make use of the NativeApplication.nativeApplication.startAtLogin property. It allows the app to automatically open whenever the user turns on his computer. It’s a great feature that’s as easy as setting the property to true, though it has a downside. When using ADL (AIR Debug Launcher), if you try to change this property, an error is thrown:

Error: Error #2014: Feature is not available at this time.
	at flash.desktop::NativeApplication/set startAtLogin()

This wouldn’t be a big deal if the developer only experienced the error, but some Linux users run builds that requires AIR apps to launch with ADL. Even though this pertains to only one DestroyTwitter user that I know of, every user deserves the same experience—especially if they do all that fancy command line code. Prior to today, I used the following code to avoid the error:

1
2
3
4
5
6
7
8
9
10
11
12
13
protected var adl:Boolean;
 
public function set openAtStartup(value:Boolean):void {
	if (adl) return;
 
	try {
		adl = false;
 
		NativeApplication.nativeApplication.startAtLogin = value;
	} catch (error:*) {
		adl = true;
	}
}

This works, but I cringe every time I need to use try/catch. While searching the depths of the flash package, looking for a solution, I came across the Capabilities.isDebugger property. It’s exactly what I was looking for, but for some reason, I never knew about it. Here’s the new implementation:

1
2
3
4
5
public function set openAtStartup(value:Boolean):void {
	if (!Capabilities.isDebugger) {
		NativeApplication.nativeApplication.startAtLogin = value;
	}
}

It’s as easy as pie and enables me to remove one more try/catch from my code and another angel gets his wings.

Reply