Skip to main content
Inspiring
March 28, 2017
Answered

External swf import into Animate/AIR for iOS app

  • March 28, 2017
  • 2 replies
  • 2004 views

Hi

I am creating apps for AIR for iOS.

I am using external swfs that I am loading into the main app.

In  testing on the Mac it worked fine once I started using Loader COntexts and Application Domains for the external swfs.

I also found that where the external swfs shared the same classes they were more likley to clash and I also needed to switch off Automatically declare stage instances in some of the files creating the external swfs.

I had it all working good but now I have published to the iPad it isnt working.

I realised that I could only use ApplicationDomain.currentDomain in AIR for iOS - whereas before I was creating a seperate ApplicationDomain for each Loader context.

Now - just using ApplicationDomain.currentDomain - some of the external swfs load and others dont.

The ones that load ok either:

aren't using external classes (I did the coding on the timeline back in the day) these load fine

or arent sharing any classes from a shared class library.

A typical error I get when trying to load the external swf when using ApplicationDomain.currentDomain

is

ReferenceError: Error #1056: Cannot create property mc1_mc on Main.

  at flash.display::Sprite/constructChildren()

  at flash.display::Sprite()

  at flash.display::MovieClip()

  at Main()[/Volumes/PASSPORT815/EY 0-6 Content Devt/Multi Media/EY Superfile/iPad Files/Move/Main.as:127]

Does anyone have any tips as to what is causing this and how to avoid this?

Best

Tommy Banana

This topic has been closed for replies.
Correct answer Colin Holgate

The more self contained the SWC is the better. All the main app should be doing is loading and unloading SWC, but any public variables in the SWC should be accessible. So for example if you want to ask the user's name in the shell app, it ought to be able to appear inside something in the SWC.

2 replies

Inspiring
March 28, 2017

Thanks Colin.

Do you control the SWC assets in the main asset eg start stop functionality - or can they be in the SWC assets as well?

I'll check that out. we are making apps for kids too - Music ones. I will check out your Heckerty!

This looks a good way to go - although quite a bit of work from here!!

Doesn't explain why some work and others do... and will mean starting again with the jib. But it is the right answer ....and so the journey of learning to code enters another chapter...

Best

Tom B.

www.abcmusic.org.uk

Colin Holgate
Colin HolgateCorrect answer
Inspiring
March 28, 2017

The more self contained the SWC is the better. All the main app should be doing is loading and unloading SWC, but any public variables in the SWC should be accessible. So for example if you want to ask the user's name in the shell app, it ought to be able to appear inside something in the SWC.

Inspiring
March 28, 2017

Thanks.

One more question.

If in the independent FLA I am using 3 main components -

say

1) an animation in a MovieClip with  a time line

2) a start stop button also as a movieclip

3) another class which a kind of interactive button allowing a user to interact with what is happening in the timeline animation.

I am guessing you wouldnt import those 3 elements into the holder FLA and recreate the game.

So do you nest all three of those elements in one Movieclip in the independent FLA so you can add it as one class from the SWC?

At the moment that is my game swf. How can  I access the whole swf as one thing from it's SWC without nesting it all inside a Movieclip?

Not sure if that makes sense....

Best Tom B

Colin Holgate
Inspiring
March 28, 2017

You can't use external SWFs with any code in them at all on iOS. What is the reason they are external? You could publish them as SWC, and include them in the ActionScript 3.0 settings for the app. Then they would work, without having to be developed all in one FLA.

Inspiring
March 28, 2017

Thanks -Colin.

Yes - the reason they are external is so I can use already developed work.

And not needing to have everything in one big FLA file.

I haven't used SWC before - can you recommend a place to find out how to use that?

Will the SWC be incorporated into the .ipa file?

Best Wishes

Tom B.

Colin Holgate
Inspiring
March 28, 2017

Great, it sounds like it could work out.

Make sure that each FLA has the entire experience is in a movieclip in the library of the independent FLA, and is using a unique linkage name. For example, if you had a game "MarioBros" you would have a movieclip in the library that had a linkage name of MarioBros. In the document class for that FLA you would do something like:

var mc:MovieClip = new MarioBros() as MovieClip;

addChild(mc);

Then in publishing settings you already have Flash(swf) checked, also check the next entry, SWC. When you test movie a SWC will be made, and that's what you add to the ActionScript 3.0 settings in the iOS FLA.

Make sure you have code that shuts down listeners when the movieclip is removed from the stage, so that as you go on to the next game the previous one is cleared from memory.

To use the game in the iOS app would be the exact same code:

var mc:MovieClip = new MarioBros() as MovieClip;

addChild(mc);

And yes, these SWCs get added to the IPA, even though they have code in them. One nice thing, it doesn't take much publishing time, the SWCs are already compiled, so only the shell FLA needs to be compiled again.

In each of the Heckerty apps I made every section is a different SWC. I'm even able to use several of the SWCs in all of the apps, there is no difference. Only the parts that are unique to that app are their own SWC, things like the current story, or the coloring book.

Meet Heckerty — a free funny interactive family storybook series for learning to read English (#1 in the Heckerty Story …