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

前端 未结 3 1610
生来不讨喜
生来不讨喜 2021-01-01 05:02

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)?

相关标签:
3条回答
  • 2021-01-01 05:14

    I'm not familiar with the rules around Apple and iPhone apps, but generally when I make apps/games, I embed everything. The advantages:

    • Your game/app is in one swf, making it easy to share
    • Your game/app loads quicker as all the assets are there at load-time
    • You're not dependant on internet access to get your assets (if you're loading them from a site) - good for an app
    • Your game/app will "just work" - no security issues, no problems with urls changing/asset site going down (if they're external)
    • If you use a swc instead of an swf (an swc can also be loaded btw), then you can also benefit from strict-typing

    The disadvantages:

    • If you need to update one of your assets, you need to republish the game/app
    0 讨论(0)
  • 2021-01-01 05:21

    The answer is yes, you can embed SWFs, but that is not the only way. You can also use normal Loader methods, with everything relative to the main SWF:

    var myLoader:Loader = new Loader();
    // iOS apps act as if the main SWF is in a folder 
    // and the other SWFs are in the same (or sub) folders. 
    var url:URLRequest = new URLRequest("loadedSWF.swf");
    myLoader.load(url);
    addChild(myLoader);
    myLoader.x = 50;
    myLoader.y = 30;
    

    With one caveat: during compile time (in the "Air for iOS Settings", in the "Included files" list), you have to list the SWFs that you want to be loaded, and they will get compiled into the IPA.

    So, no you cannot call to external SWFs, but you certainly can access other SWFs using the embed tag, or using (what might be called) IPA embedding.


    Edit:

    Since the question and title have changed a bit since I first answered this, here is a more generic summary. Apple does not allow loading local SWFs in the same way that you would be able to if using Flash Player on a website. There is no way to load an SWF (or anything else) using "relative" or "local" references in an i-device unless that content is compiled into the app. This does not apply to some types of "remote" SWF loading, and also does not apply to Actionscript "Native" coding, but that is not what the (original) question was about.

    0 讨论(0)
  • 2021-01-01 05:27

    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.

    0 讨论(0)
提交回复
热议问题