Search code examples
iphoneactionscript-3air

Conditional header include in AS3


I have a Flash CC/AS3 document which I intend to deploy on both iOS and Android platforms.

What I need to do next is integrate the app with Facebook. What I thought was the most logical way would be to have a class which handles all of the Facebook interaction stuff and calls on the appropriate method whether we have compiled for Air for Android or Air for iOS. I don't think this would be too difficult to do.

The problem arose when I started playing around with Persistant Login. To accomplish this on iOS I need to include .ane files into my .fla. Fine, so at this point I duplicate the .fla and have 1 for Android and 1 for iOS (This was the plan all along).

So in the iOS app I next have to import com.sbhave.openUrl.*; which references an .ane file. I was hoping that I would be able to do something like

try{
   import com.sbhave.openUrl.*;
}
catch(e){
   //Set some constant to let us know that we are on android
}

The alternative (I think) would be to make all changes for iOS, do a diff and create a patch to quickly swap in and out the iOS native extensions at build time. Does anybody have any suggesions how I can catch a failed import, or import conditionally based on whether or not the .ane file is present.

Thanks

PS..

OH yeh, I forgot to mention the reason this is so important is that the Air for iOS can't be ran on my PC with the extensions included, and it is a lot of work compiling + installing every time I need to test.

PPS..

This problem isn't specific to Facebook Persistent log in as there are other native extensions which will be required for various bits. The focus of the question is whether tha AS3 code can conditionally include a header file or process different includes based on paramaters set in the .FLA


Solution

  • For anyone else having a similar problem I have resolved this by doing the following: I created a compile-time Constant that CONFIG::iOS which I set to true in the iOS app and False in Android.

    Any code that relies on 3rdparty .ane or .swc files being included is enclosed in a block like

    CONFIG::iOS
    {
      //iOS Specific
    }
    

    Thanks to http://divillysausages.com/blog/as3_conditional_compilation