Skip to main content
Frédéric C.
Inspiring
Jul 17, 2011 3:26 PM UTC
Question

Cloning MovieClips in AS3 without using linkage names?

Hi,

Flash on iOS doesn't allow the use of SWF files having linkage names or containing AS code. It is a problem for me, since I have my assets in external SWF files. For example, let's say that I have a rotating apple animation in an FLA file, in the main timeline. I compile this FLA into a SWF, and then I load the SWF file and add it to my stage. It's working fine.

But now I want to intanciate several apples on my stage. Since I can't create various instances of this object (I don't have a linkage name for that), the only solution would be to be able to duplicate the only instance I have into several clones. I looked around the web, but it seems there is no real way to clone a movieclip, like with duplicateMovieClip() in AS2. All the solutions I tried didn't work.

So please, could you tell me if there is a way to circumvent this limitation and intanciate several copies of the same SWF animation on the stage?

Thank you very much!

Frédéric

This topic is closed to new replies. Start a new post to keep the conversation going.

7 replies

Colin Holgate
Inspiring
Jul 17, 2011 3:32 PM UTC

I believe that if you put movieclips on the stage of your loaded swf, you can then get the class name from that, and then get a new one of those from the loaded swf's library. Look into this:

Class(getDefinitionByName(getQualifiedClassName(obj)));

where obj would be the instance on the loaded swf's stage.

I haven't tried this, but it might work out.

Translate
Frédéric C.
Inspiring
Jul 17, 2011 3:47 PM UTC

Thank you Colin for your fast reply.

I tried your code, but basically what it returns is the MovieClip class. So when I intanciate a new object with this computed class, it creates an empty MovieClip. In other words :

clone = new Class(getDefinitionByName(getQualifiedClassName(obj)));

is equal to

clone = new MovieClip();

So it doesn't create an object with its own predefined contents, like you would expect from a MovieClip with a linkage name in your library.

Translate
Colin Holgate
Inspiring
Jul 17, 2011 3:52 PM UTC

Next up might be to getdefinitionbyname(instance.name), and name the prototype instance with the same name it has in the library.

Translate