views:

269

answers:

2

I am trying the following but every once in awhile the nativeApp is not defined.

var nativeApp:Object =  getDefinitionByName("flash.desktop.NativeApplication");
nativeApp.nativeApplication.exit();

I am confused why sometimes getDefinitionByName("flash.desktop.NativeApplication") resolves and other times it does not.

I am trying to resolve this problem to address the following issue in flexcover - code.google.com/p/flexcover/issues/detail?id=33

Update - here is the class I am attempting to fix: http://code.google.com/p/flexcover/source/browse/trunk/CoverageAgent/src/com/allurent/coverage/runtime/AbstractCoverageAgent.as CoverageAgent.swc is an actionscript library called by the unit tests to exit the flexcover air application used to determine the code coverage of the unit tests. The flexcover air application only exits about the half the time and it is causing problems for our maven builds to execute successfully.

+1  A: 
NativeApplication.nativeApplication.exit();
ZaBlanc
+1 `nativeApplication` is a static field, so it should be accessed like a static field.
ilikeorangutans
What import should I use? When I try import flash.desktop.NativeApplication in the actionscript library then it could not be found.
Vincen Collins
I don't know. Aren't you using Flash Builder? After NativeApplication hit Control-Space. Who remembers imports anymore? :-)
ZaBlanc
Do you have the AIR libraries in the build path?
ilikeorangutans
ok, I have included the airglobal.swc in the build path. Thanks! But now I am back in the same boat where "Variable flash.desktop::NativeApplication is not defined." This problem seems to be somehow related to executing the testrunner swf from an ANT script. Could that be causing this problem of the variable not resolving?
Vincen Collins
A: 

nativeAppilcation is a static field. It does not need to be called on an object. So you do not have to call getDefinitionByName("flash.desktop.NativeApplication"). Just invoke exit as follows:

NativeApplication.nativeApplication.exit();

Flash Builder or Flash Pro will include the library for you. If are not using the IDE, import flash.desktop.NativeApplication;

Rajorshi