Skip to main content
Known Participant
June 8, 2011
Question

Air for IOS Including files in IPA (SWF)

  • June 8, 2011
  • 9 replies
  • 28843 views

I've added a SWF file to the included files list in Publish Settings that I would like to load.

Any ideas on how to get it to work?

Here is my code:

import flash.net.URLRequest;

import flash.display.Loader;

import flash.events.Event;

import flash.events.ProgressEvent;

import flash.filesystem.File;

function startLoad()

{

var file:File = File.applicationDirectory.resolvePath("SomeFile.swf");

var mLoader:Loader = new Loader();

var mRequest:URLRequest = new URLRequest(file.url);

var context:LoaderContext = new LoaderContext();

context.checkPolicyFile = true;

context.securityDomain = SecurityDomain.currentDomain;

context.applicationDomain = ApplicationDomain.currentDomain;

mLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);

mLoader.contentLoaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, handleGlobalErrors);

mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);

mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);

try {

     mLoader.load(mRequest, context);

} catch (error:Error) {

     mLoader.load(mRequest);

}

}

function handleGlobalErrors( evt : UncaughtErrorEvent ):void

{

     evt.preventDefault();

}

function onCompleteHandler(loadEvent:Event)

{

     addChild(loadEvent.currentTarget.content);

}

function onProgressHandler(mProgress:ProgressEvent)

{

     var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;

     trace(percent);

}

function ioError(event:ErrorEvent):void {

}

startLoad();

This topic has been closed for replies.

9 replies

Inspiring
December 2, 2011

look into importing your swfs into the main .fla library via a .swc file...

//---

one thing i learned is that an externally loaded swf that has AS will not run, but if you copy/paste all frames from that swf's source .fla (even code) into a movieclip symbol in your main .fla (keeping imported assets in separate folders for organization) code will run in that movieclip if it's exported for AS and placed on the stage via addChild()... the only thing is, any code inside of nested movieclips within the child you added will not run...

November 13, 2012

Will iPad allow access to a MovieClip if it's mx.flash.UIMovieClip? Does iOS count UIMovieClip as code?

Thanks in advance,

Suat

Inspiring
November 29, 2011

Thanks for the responses guys, I also think it won't work - because it seems it's not really a security issue, but instead due to the fact that iOS needs all ActionScript code to be compiled into native code ahead of time (unlike Android), so for external swf files with code to work, that code would need to be compiled, or interpreted on the fly which is against the rules on iOS.

I've seen solutions involving packing swfs into swc files, but in my case I will probably just import my swf's into the main fla before publishing.

Inspiring
November 29, 2011

Great thread, I'm also looking for the latest and greatest workaround to be able to load in my external swfs that contain AS3 code.

Can Justin, or anyone else, confirm that adding the following:

Security.allowDomain(this.loaderInfo.loaderURL);

or

Security.allowDomain("*");

to the swf that gets loaded in, will allow it to execute properly, if it contains ActionScript?

-rich

Justin Putney
Known Participant
November 29, 2011

Sorry, Rich. I don't current have an iPad on hand to test.

jfweber
Inspiring
September 26, 2011

Is there actually support for external XML files as external assets like with the SWFs?

Colin Holgate
Inspiring
September 26, 2011

You can use xml, sounds, images, or swfs, that are part of the IPA file.

jfweber
Inspiring
September 26, 2011

Thanks!

Participant
August 26, 2011

I have a similar issue.  I'm loading an swf thats included in the ipa that has symbols exported for actionscript but no other code.  The strange thing is that if I do a debug build it works fine on the iphone and ipad.  However when I try to do a release build I get

Exception in thread "main" java.lang.Error: Unable to find named traits:

public::Name of art asset

at adobe.abc.Domain.resolveTypeName(Domain.java:225)

at adobe.abc.Domain.resolveTypeName(Domain.java.142)

at adobe.abc.GlobalOptimizer$InputAbc.resolveTypeName(GlobalOptimizer.java:272)

at adobe.abc.GlobalOptimizer$InputAbc.resolveSlotType(GlobalOptimizer.java:947)

at adobe.abc.GlobalOptimizer$InputAbc.resolveType(GlobalOptimizer.java:535)

at adobe.abc.GlobalOptimizer$InputAbc.resolveTypes(GlobalOptimizer.java:448)

at adobe.abc.LLVMEmitter.generateBitcode(LLVMEmitter.java:239)

at com.adobe.air.ipa.AOTCompiler.convertAbcToLlvmBitcodeImpl(AOTCompiler.java.446)

at com.adobe.air.ipa.BitcodeGenerator.main(BitcodeGeneratore.java:81)

Compilation failed while executing : ADT

I've googled around for this and it sounds like I shouldn't be able to load the swf externally even if included in the IPA but it's strange that it works for the debug IPA...

Any information on this would be appreciated.

Participating Frequently
August 26, 2011

As per adobe the compiler fails because stack overflow issue in the action script.currently they said

"You can package your application in interpreter mode. (“Packaging method: Fast (packaging takes several seconds, application runs slower than release build option in Flash Builder)."

Iam assuming they recommend the debug mode(requested them to confirm but did not get any update yet,if i hear something then will post here)The other solution is to run on a machine with higher RAM of your current machine and test.The last option is they got the solution now but do have to wait until there next release,which is coming soon.

Let me know if you got it working on higher RAM machine,I will also try and post the updates.

Participant
July 25, 2011

I did put them all in a folder and include the folder in the iOS publish settings, but since all of the 50+ SWFs contain actionscript, if I am reading your response correctly, it looks like I will need another solution for iOS.

By the way, it does work fine under Android, just not under iOS.

Do you know if there is a way to include a bunch of .FLAs into one "Air for iOS" app?  In other words, when I publish, CS5.5 will just compile each of the FLAs into one Air for iOS app?

Justin Putney
Known Participant
July 25, 2011

I would use JSFL to either:

  1. Remove the AS from every file -OR-
  2. Make each SWF timeline into a symbol and include them in the main FLA (so there is only 1 file)

You could look into use a runtime library, either SWF or FLA, but both options would likely require you to bring every timeline into 1 library file.

Additionally, you might also be able to include something like the following code in each SWF that will allow you to load them in:

Security.allowDomain(this.loaderInfo.loaderURL);

or

Security.allowDomain("*");

reference: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Security.html#allowDomain%28%29

I haven't tried it, but it may work.

Also check out:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/LoaderInfo.html

Participant
July 25, 2011

When you say that "external SWFs cannot contain actionscript", does that include SWFs that were built into the .ipa by going to the "File->Air for iOS Settings..." and including SWFs via the "Included files" part of the "General" tab?

I have a project with 50+ SWFs in it (all that I have the .FLA files for) and all have actionscript in them.  I am looking for a painless way to convert it to Air for iOS.

Justin Putney
Known Participant
July 25, 2011

It does apply to the "included files." The easiest way to include them is to put them all in a single folder and include the folder within the iOS Publish Settings.

Justin Putney
Known Participant
June 15, 2011

I'm testing an iPad app at the moment and I can confirm, that you can:

  1. include external SWFs in an IPA package
  2. load the SWFs with a Loader and URLRequest using a relative path

The external SWFs, however, cannot include any actionscript (even stop() actions). When the SWFs contained actionscript: their audio would play in the background, the COMPLETE would not fire, and there was no indication of an IOError or any other failure.

I spent a while trying to figure this out before finding this thread, so I wanted to spell it out plainly for anyone else in this situation.

June 8, 2011

Whats the issue you are facing? Are you not able to generate the ipa for your project? Or you are not able to execute/run ipa on your device?

Known Participant
June 8, 2011

Everything works with the IPA. I'm able to generate it just fine. It loads perfect on my iPad, but I'm having trouble accessing the local SWF that I attached to the IPA publish settings.

How can I access files that I've included via the Publish Settings (Included Files) list?

I basically want to load an .swf file into my ipad app from the local directory on the ipad. Am I accessing the local directory correctly in my code above?

Known Participant
June 9, 2011

Yes, external swf with script won't work, but I have successfully loaded  many swf by controlling everything from my index file. Did you  downloaded the Latest AIR SDK and AIR 2.6 which supports both ios and  android? What version of flash IDE?

Sample format:

instead of debug use ipa-test and make sure you have all the files within your package

C:\AdobeAIRSDK\bin\adt.bat -package -target ipa-test -storetype pkcs12 -keystore [KEYFILE].p12 -storepass [KEY PASSWORD] -provisioning-profile [MOBILE PROVISION FILE].mobileprovision [IPA NAME].ipa [XML FILE NAME].xml [SWF FILE NAME].swf Icon_29.png Icon_48.png Icon_57.png Icon_72.png Icon_512.png Default-Landscape.png Default-Portrait.png Default-PortraitUpsideDown.png Default-PortraitLandscapeLeft.png Default-PortraitLandscapeRight.png


Can you post an example of your XML file?

I have the latest AIR runtime.

Thanks