Skip to main content
August 3, 2011
Answered

You can't put a common MC inside 5 MCs in AS3?

  • August 3, 2011
  • 2 replies
  • 1442 views

Simple question: In AS3 you can't do sharing of a MC between more MCs, right? In AS2, you can. How can I work around this?

Let me be specific: in ActionScript *TWO* I do something like this:

       movie.attachMovie(LargeImage, "image", 20);

LargeImage = movie clip of 400 x 480.

Now... the thing is: I do this for 20 MovieClips but they all REUSE the same original MC apparently (with no memory increase, of course). If I animate the MC, it will animate within all 20 MovieClips. I'm using a mask to show only portions of the MC, but I think that's not important.

But in ActionScript 3 this wouldn't work, right?

Because in AS3 every time we .addChild, the child is REMOVED from the parent, so the same MovieClip / Sprite couldn't be in 2 places at once.

How would you work around this without creating a separate instance of the "LargeImage" MovieClip for each object? Note that I don't want to use BitmapData & CopyPixels: the object may be animated.

This topic has been closed for replies.
Correct answer Ned Murphy

Hello Ned, thanks for answering ::- ).

However, I am unsure if that would work the way it does in AS2.

I'm asking this because in AS2, my MC contains 2 frames: an image of 400 x 480 in frame 1 and the same image in frame 2, but with a Glow effect to it. I'm slamming this MC into 200 other MCs (don't ask ). Still, I see no dramatic increase in memory usage. It's about 2 MB more.

So what you're saying is that:


- 200 new instances of the 2-frame MC with the Image are created.

- As the imageMC goes from frame 1 to frame 2 and back again, all the 200 MCs in which that imageMC is placed will look exactly the same at a given point in time NOT because they're using the same imageMC, but because all their imageMCs are switching their frames in the same time, right?

My explanation may be vague so I'll also word it another way: I got 200 MCs and, according to your insight, in each of them, there is a separate instance of imageMC *both* in AS2 or AS3. The only reason I'm not seeing horrible memory increase (due to 200 multiplied by 400x480 pixels) is because Flash Player somehow caches the imageMC. Even if that imageMC has 2 frames in which in the 2nd frame I apply a glow filter.

And I'm seeing all my 200 MCs glowing in the same time because the imageMC in each of them glows at the same time.

(Ignore the fact that I can't actually see 200 images of 400 x 480: I'm using some scaling & stuff. Ignore the entire irrationality of the situation for that matter ::- D)


When you use attachMovie you are creating a new instance of an object from the library.  The same thing happens when you use the AS3 code I showed.  If things are changing frames similarly, that could be due to them all being added at pretty much the same time (such as in a for loop).  If you were to stagger the creation you would probably see things not happening in a synchronized manner.

2 replies

relaxatraja
Inspiring
August 3, 2011

-

Darshan_Rane
Inspiring
August 3, 2011

You can duplicate the movieclip.

--

http://www.darshanrane.com

August 3, 2011

I'm not sure what you mean by "duplicate". We're talking about AS3 here, not Flash CSx Library. I can't "duplicate" a MC.

Darshan_Rane
Inspiring
August 3, 2011

You can duplicate a clip on runtime  or a movieclip which is generated on runtime

Check this,

senocular.com/flash/actionscript/?file=ActionScript_3.0/com/senocular/display/duplicateDisplayObject.as

--

http://www.darshanrane.com