Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to embed or load SWFs when making iphone apps (Is it allowed by Apple)

I am a little confused on whether to embed swfs or load them when making apps for the iphone. Does anyone know what are the advantages of each (which is preferable to use)? I know that embedding swfs should be a little faster than loading them but is that all?

Also and this is kind of important, I read that Apple will reject any app with external swfs?? Is that indeed correct? If so, will embedding or loading said swfs solve this problem?

Thanks in advance

EDIT: after some searching around, turns that Apple does have problems with loading external swfs, u can still do it, but your swfs need not have any actionscript attached, here is a link http://whizzkid74.blogspot.com/2010/12/air-for-iphone-loading-external-swf.html It doesnt say anything about embedding swfs however, so my question is this: can u embed swfs when writing apps on the iphone??

EDIT To clarify, when i say external SWFs. I mean SWFs that are found on your system locally but you need to add them to your program since they contain MovieClips or Sprites etc... that u need. I didn't mean SWFs that you need to download from a website or an online source. (hope that clarifies things)

EDIT Changed the question's title...Problem solved, thanks for all the help guys and happy new year =D

like image 881
r3x Avatar asked Dec 17 '22 05:12

r3x


1 Answers

Update, Oct 2012:

In Adobe AIR 3.5, adl is introducing a feature called "multiple SWF support" that allows the use of Loaders to load SWFs delivered in the .ipa (local files, not from servers) to have code in them. The adl compiler AOT compiles SWFs that are included in the .ipa, allowing them to be loaded and work under iOS.

AIR 3.5 is currently in beta at the time of this writing, available on the adobe labs site:

  • AIR 3.5 on Adobe labs website
  • AIR 3.5 release notes

Note that this feature requires -swf-version=18 or greater of the root SWF (not necessarily the assets being loaded) and AIR namespace ending in 3.5 in the application xml file.

Older answer:

I wanted to update this answer because I've learned a lot about this issue since I first looked into it.

The root of the issue is that, when making iOS apps with AIR, Apple TOS disallows runtime interpretation of code - and this includes SWF bytecode. So loading SWFs with code in them (even simple animation commands like stop(), gotoAndPlay(), etc) is disallowed and will not work via a Loader (prior to AIR 3.5).

  • Note that it's perfectly fine to load SWFs for their vector graphics content. The graphics will display, but the code will not execute.

However, there are a few workarounds for this. Both workarounds avoid a Loader by compiling assets with code in them into the main SWF, because once they're part of the main SWF, the AIR compiler (adt) will cross-compile the code into 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 graphical assets (.fla file) into SWCs (or export SWCs from symbols in your library), then compile your main swf against these SWCs, this goes through the compiler and actionscript code will execute on iOS devices.

Using SWFMerge for [embed]ed SWFs

Embedding assets into SWFs is very easy, 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 scenario, if gameLevel.swf has code in it, it typically wouldn't work in iOS, because new gameLevel() would create a Loader and interpret SWF bytecode. 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: new gameLevel() now results directly in an instance of your asset - NOT a Loader.

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 if you have trouble.

Using Loaders

Prior to AIR 3.5, if you use a Loader to load a SWF file (whether this swf is included in your IPA or served from a webserver), the target SWF graphics will load just fine, but no code inside the SWF will execute, again because this is disallowed by Apple's TOS.

As of AIR 3.5, packaging SWF files in the .ipa as assets, using a Loader will work even if they contain code as this code is now AOT-compiled by adt. This requires -swf-version=18 or greater of the root SWF (not necessarily the assets) and AIR namespace ending in 3.5 in the application xml file.

However, it is technically possible to interpret SWF bytecode, it's simply an App Store legal restriction not to. If you only want to test on an iOS device and won't be distributing your app via the App Store, you can compile your SWF using adt's -target ipa-test-interpreter option, and Loading SWFs with code in them will work.

like image 190
Jeff Ward Avatar answered Jan 21 '23 13:01

Jeff Ward