I use my code in both an Adobe Flex and in an Adobe Air application. As I want to use the native menus of Adobe Air I want to prevent that my self-built menu is being added to the Air application. Thus, I need to figure out if the code is running in a Flex or in an Air application. I do this by using the following structure:
var airApp:Boolean = false;
try{
if(NativeApplication.nativeApplication) airApp = true;
}catch(error:Error){}
if(!airApp){
addChild(generalMenuSprite);
}