Update, October 2012:
In Adobe AIR 3.5, adl introduces a feature called "multiple SWF support" that allows you to use Loaders to load SWF files delivered in .ipa (local files, not from servers) to have code in them. The ADL AOT compiler compiles SWFs that are included in .ipa, allowing them to boot and run on iOS.
AIR 3.5 is currently in beta testing at the time of this writing, available on adobe labs:
Note that this function requires -swf-version = 18 or more root SWF (not necessarily downloadable resources) and an AIR namespace ending in 3.5 in the xml application file.
Old answer:
I would like to update this answer because I learned a lot about this problem since I first studied it.
The root of the problem is that when creating iOS apps with AIR, Apple TOS prevents code from being interpreted at run time - and this includes SWF bytecode. Thus, loading SWFs with code in them (even simple animation commands, such as stop (), gotoAndPlay (), etc.), are Forbidden and will not work through Loader (before AIR 3.5).
- Please note that to download vector image files to download SWF files is completely normal. A graphic is displayed, but the code will not be executed.
However, there are several workarounds for this. Both workarounds avoid Loader by compiling the assets with the code in them in the main SWF, because when they are part of the main SWF, the AIR (adt) compiler cross-compiles the code in objective-c and everything will work fine on iOS devices.
Using SWC Libraries
This is the best option for iOS development. If you compile your graphic objects (.fla file) into SWC (or export SWC from characters in your library), then compile your main swf against these SWCs, this will go through the compiler and ActionScript code that will run on iOS devices.
Using SWFMerge for [embed] ed SWF
Investing in SWF is very simple and looks like this:
[Embed(source="GameLevel.swf")] private var GameLevel:Class; public function main():void { var my_level:* = new GameLevel(); addChild(my_level); }
In this case, if there is code in gameLevel.swf, it usually does not work on iOS, because the new gameLevel () will create a Loader and interpret the SWF byte code. But if you first run the above SWF through my tool called SWFMerge, it will take your embedded SWF and merge it into your root SWF. Then ADT will compile your main swf (including embedded code) into objective-c, it will work on iOS, and note: now the new gameLevel () is now displayed directly in the instance of your asset - NOT a bootloader.
The SWFMerge tool is here:
http://www.onetacoshort.com/temp/SWFMerge_alpha.swf
Let me know in the comments if this workaround works for you or you are having problems.
Using Loaders
Prior to AIR 3.5, if you use Loader to download a SWF file (whether this swf is included in your IPA or served from a web server), the target SWF graphics will load just fine, but no code inside the SWF will execute , again, because it is forbidden by Apple TOS.
As in AIR 3.5, packing SWF files in .ipa as assets using Loader will work even if they contain code, as this code is now AOT-compiled adt. This requires -swf-version = 18 or more from the root SWF (not required for assets) and the AIR namespace ending in 3.5 in the xml application file.
However, itβs technically possible to interpret SWF bytecode, itβs just a ban on the use of the App Store. If you want to test only on the iOS device and will not distribute your application through the App Store, you can compile SWF using the adt -target ipa-test-interpreter parameter, and loading SWF with the code in them will work.