开发者

Is reference lost?

开发者 https://www.devze.com 2023-02-05 12:48 出处:网络
First a bit of code: var mc:MovieClip = new MovieClip(); mc.graphics.lineStyle(2, 0x000000); mc.graphics.beginFill(0xFF00000)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消