orety
orety

Reputation: 1

Is reference lost?

First a bit of code:

var mc:MovieClip = new MovieClip(); mc.graphics.lineStyle(2, 0x000000); mc.graphics.beginFill(0xFF00000) mc.graphics.drawRect(10, 10, 100, 100); var array:Array = [mc];

this.addChild(array[0]);

mc = new MovieClip();

this.removeChild(array[0]); this.addChild(array[0]);

I would expect it to update reference held in array and add empty MovieClip to the stage. Is that wrong assumption then?

Thanks

Upvotes: 0

Views: 48

Answers (1)

Keith Irwin
Keith Irwin

Reputation: 5668

Yes. Changing which movie clip mc refers to does not change which movie clip array[0] refers to. It still refers to the old one. Instead, change the last line to this.addChild(mc); or add another line which says array[0] = mc; between the removeChild and the addChild which follows it.

Upvotes: 2

Related Questions