1

Flash is duplicating my MovieClip instances for some reason. They are a series of three clips that are on the main timeline, with no animation on the main timeline, though there is some inside the clips.

After doing gotoAndStop backwards on the timeline, the three clips, pic1, pic2, and pic3, become duplicated. Well, actually, it seems to create a completely new instance of these three clips. After this duplication, the new clips seem to "override" the old ones, since referring to them always refers to the new one, but they are both still present on the stage.

I ran the following test to see what would happen:

for (var i:int = 0; i < this.numChildren; i++) {
    trace(i + ": " + this.getChildAt(i).name + ": " + this.getChildAt(i));
}

And I got this baffling output:

0: pic3: [object pic3holder_99]
1: pic2: [object pic2holder_100]
2: pic1: [object Pic1]
3: pictureDesc: [object pictureDesc_98]
4: pic3: [object pic3holder_99]
5: pic2: [object pic2holder_100]
6: pic1: [object Pic1]
7: switchBTN: [object switchButton_101]
8: overBTN: [object MovieClip]

Yes, those are sets of MovieClips with the same instance name. Has anyone ever encountered this before? What on Earth could be going on?

EDIT: I've found that it seems to only occur when I re-order the MovieClips with ActionScript. It seems to think the MCs are out of order, then re-adds them. Is there any workaround to this issue?

Alexis King
  • 43,109
  • 15
  • 131
  • 205
  • You should post some more code - my guess is that your code is creating these clips on the fly and it probably doesn't check whether the clips already exist or not, so they get created again. I may be wrong, I'm just guessing. – xxbbcc Feb 29 '12 at 03:16
  • @xxbbcc: These clips are only on the stage, placed via the IDE. There's actually relatively little code in the project, and these clips are never created dynamically. – Alexis King Feb 29 '12 at 03:20
  • On the main timeline, are there multiple keyframes for a given instance? If there are, make sure all key frames for that instance have the same instance name. Actually, this problem isn't the problem now that I've looked more closely at the output. It does indeed, sound very strange. – DNJohnson Feb 29 '12 at 03:22

1 Answers1

2

If you add MovieClips to the stage, via the IDE, you should never remove then or put them back onto the stage via ActionScript. More generally, you should never use ActionScript to change their order in the display list. Otherwise Flash gives you ownership of the MovieClip you removed, and then put it back again (create a new one) when you go back to the frame.

If you need to reorder the clips, try to do it directly on the timeline, in the IDE. If your animation requires something more complex, the solution might be to do it all in ActionScript (always the most flexible solution and the one with the less surprises anyway).

laurent
  • 88,262
  • 77
  • 290
  • 428