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 开发者_StackOverflowthen?
Thanks
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.
精彩评论