Copy childs of one movieclip to another movieclip

白昼怎懂夜的黑 提交于 2019-12-23 06:12:02

问题


i have two movieclips container.

MovieClip_1 MovieClip_2

now MovieClip_1 contains one child _child_1. now by pressing button i want to add that _child_1 of MovieClip_1 to MovieClip_2 without removing from MovieClip_1.

i tried following code in button press event but it removes _child_1 from its past container.

var mc:MovieClip = MovieClip(MovieClip_1.getChildAt(0));
MovieClip_2.addChild(mc);

回答1:


It is not possible to add the same display object to two different parents. Trying to do so will remove the display object from its former parent.

Instead, consider creating a new instance of your child's class and add this instance to the container MovieClip_2.




回答2:


What Jens said is correct. There is however a class for copying DisplayObjects. Check out http://www.senocular.com/flash/actionscript/?file=ActionScript_3.0/com/senocular/display/duplicateDisplayObject.as.



来源:https://stackoverflow.com/questions/6911746/copy-childs-of-one-movieclip-to-another-movieclip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!