Porcelain
Porcelain

Reputation: 11

Removing child from MovieClip's timeline

I'm loading swf file and creating MovieClip object from Linkage in swf Library. There are two frames in MovieClip timeline, separated, no tween. There is no code in frames or at objects. All the objects in frames are MovieClips, each of which contains one frame with graphic object in it. There are 12 objects at first frame and 1 at second frame.

swf file first frame

I'm trying to remove one of the objects from first frame:

var mc:MovieClip = new clss() as MovieClip;
trace("total frames: "+mc.totalFrames);
mc.gotoAndStop(1);
trace("first frame numChildren: "+mc.numChildren);
mc.removeChildAt(0);
trace("first frame numChildren: "+mc.numChildren);
mc.gotoAndStop(2);
trace("second frame numChildren: "+mc.numChildren);
mc.gotoAndStop(1);
trace("first frame numChildren: "+mc.numChildren);

And I got:

total frames: 2
first frame numChildren: 12
first frame numChildren: 11
second frame numChildren: 1
first frame numChildren: 12

Why is there again 12 objects?

Upvotes: 0

Views: 69

Answers (1)

null
null

Reputation: 5255

In a nutshell: Don't use frames.

In a watermelon: A frame is like a state. You can manipulate the state, but whenever you go back to the frame, the original state is recreated.

This is why frames are a terrible choice when it comes to controlling the flow of a program: they do not keep their state.

That's why you shouldn't use frames to organise states of an object. At least not if you want to change its state.


There's a contradiction in your statement:

and has one frame with graphic in it. There are 12 objects at first frame and 1 at second frame.

It either has one frame with a graphic or it has 12 and 1 object on frame 1 and 2 respectively, which means 2 frames with graphic.


You already have a class name associated with your object: clss This is not very descriptive. It should also start with a capital letter. Circles or CircleGroup sounds like a better fit given the image in your question. Now all you have to do is add methods to the class that change the state of the object from having 12 circles to only 1.

Given the simplicity and the apparent randomness of placement, I would not create library symbol and do this all in code. To do this, you have to associate the symbol of the circle with a class name in order to create instances of it.

Upvotes: 1

Related Questions