27 February 2012
When doing game development for Android or Blackberry Tablet OS with Adobe AIR, you can load SWF files on the fly at runtime; with AIR for iOS, there is no such option. On Android or Blackberry Tablet OS the code is interpreted from ActionScript bytecode, whereas for iOS all code must compiled from ActionScript bytecode to native bytecode as a single IPA file, which you can only create from a single SWF.
If your game has dozens of levels and each level is a SWF, then compiling for iOS can be a challenge. When you're in the game programming and testing phase of development, you can use
ipa-test-interpreter switch in the compiler settings, and your game will run as it would on Android or BlackBerry Tablet OS. However, Apple will not accept games built using this approach in the App Store, so you need a different approach for your release build.
One solution is to compile each level to a SWC library, and then link all the SWCs into a single SWF file (see Figure 1).
If you're using Flash Builder, you'll need to use a Flex Library Project (see Figure 2), which outputs a SWC file, instead of an ActionScript project, which outputs a SWF.
In Flash Professional CS5.5, you can use an option in the Publish Settings dialog box to generate a SWC instead of a SWF (see Figure 3).
When you use the technique outlined in this article for your iOS game development, you'll need to instantiate new levels at runtime instead of loading them dynamically. Remember, it is possible to load SWF files on iOS, but the code inside them won't be interpreted. Loading a SWF in this way is useful for graphical assets such as animations or vector graphics. You can create a library full of symbols and simply pick the symbol that you want to use.
Lastly, note that this technique works for ActionScript 3.0, but not ActionScript 2.0.
For information on combining several SWFs into a single SWF, see my article Joining multiple SWF files into one SWF for iOS deployment.