Skip to main content
Inspiring
August 23, 2012
Question

How do you work around code not functioning in loaded SWFs on iOS.

  • August 23, 2012
  • 13 replies
  • 2497 views

Hi,

I came across a post that suggested that in iOS, code does not function in loaded SWFs and a quick test demonstarted that this was true.  I'm just wondering if anyone has come up with a workaround for this.

I'd appreciate any insight you can give me.

Best,

Chris

This topic has been closed for replies.

13 replies

Nimisha1
Participating Frequently
December 12, 2012

Hello everyone,

Feature Multiple SWF on iOS has been introduced in AIR 3.6 Beta build and you can download it from here http://labs.adobe.com/downloads/air.html

Also to know more about the feature refer to http://blogs.adobe.com/airodynamics/2012/11/09/packaging-and-loading-multiple-swfs-in-air-apps-on-ios/

We would like to hear your feedback, please let us know if you face any issues.

Thanks,

Nimisha

Colin Holgate
Inspiring
December 12, 2012

That article talks about the feature being introduced a while ago, in an early AIR 3.5 build. What is new in 3.6?

Nimisha1
Participating Frequently
December 12, 2012

Hi Colin,

This feature was dropped from the AIR 3.5 build and was there only in some early beta builds of AIR 3.5. Now in AIR 3.6 we have again added this feature.

There is a minor change in AIR 3.6 that swf reloading is not allowed and attempting same will result into the error 3764: Reloading a SWF is not supported on this operating system.

Jeff__Ward
Inspiring
September 3, 2012

Chris,

The reason external SWFs with code in the doesn't work is that ADT cross-compiles your root SWF (and only your root swf) into objective-c code consumable by an iOS device.

I created a workaround for this problem - as long as you embed your asset like this:

    [Embed(source="gameLevel.swf")]

      private var gameLevel:Class;

...

    addChild(new gameLevel());

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.  The result is that ADT will compile your code into objective-C, it will work on iOS, and note: new gameLevel() now results in an instance of your asset - NOT a Loader.

The SWFMerge tool is here:

http://www.onetacoshort.com/temp/SWFMerge_alpha.swf

LMK if this workaround works for you or if you have trouble.  Cheers!

-Jeff

Inspiring
September 4, 2012

Hi,

Thanks to Chris and Jeff for the suggestions.  I will look deeper into both.  To meet my immediate needs we simply took an approach where we contolled the loaded SWF from the parent by referencing frame labels within the loaded clip.  When I do test the other methods, I will let you know my results.

Best,

Chris

Inspiring
August 23, 2012

I don't know what your particular use-case is, but if you are the author of the swfs, you could pull out the shared code to a library project and consume the project or swc in both your SWF and mobile air versions.

Inspiring
August 24, 2012

Hi Chris,

Thanks for your reply. The loaded SWFs have timelines with bits of code along the way and each timeline is a bit different. In this particular case I'm guessing the approach you suggested wouldn't work, but have you used this approach successfully?  Also I guess I'm not clear on why the swc is consumed by the loaded SWFs and the parent app,  I pressume that if it;s only on the swf side you'd see the same failures, but I'm not clear how consuming the swc in both resolves this.  If you have the time and are willing to elaborate, I would be grateful for your insight.

Best,

Chris

Inspiring
August 24, 2012

I have not reused code between a SWF project and a Flex Mobile Project.  However, I have created Flex Library Projects with common code such as database access, error handling functionality, etc. that have been reused in multiple Flex Mobile Projects.  While these are all in the same workspace in Flash Builder and are referenced directly by the executing project, I assumed that the SWC files that contain the compiled libraries could be imported into a SWF project and referenced there.  Of course, this would mean de-coupling all of your functionality from the timeline into a reusable library, and then referencing the necessary library function from the timeline.  This may not be possible for your case if the functionality relies heavily on properties contained within the calling application.

Another option might be to compile your actual SWF out as a SWC from Flash and reference that from Flash Builder.  Again, I do not have experience with SWFs and Flash, but it is an idea.