如何从舞台上删除一堆动态创建的东西?
我试图一次性从舞台上删除一堆不同的东西。 我有 3 个动态创建的文本字段和 2 个动态创建的影片剪辑。 我通过我的文档类将它们添加到舞台上,购买创建它们,编辑它们的属性,然后...
addChild(myText1);
addChild(myText2);
addChild(myText3);
addChild(myMovieClip1);
addChild(myMovieClip2);
我想将它们全部删除,我已经尝试过...
removeChild(myText1);
等等
但这不起作用。 谁能帮助我。
I am trying to delete a bunch of different things from the stage all at once.
I have 3 dynamically created text fields and 2 dynamically created movie clips.
I added them to the stage through my document class buy creating them, editing their properties and then...
addChild(myText1);
addChild(myText2);
addChild(myText3);
addChild(myMovieClip1);
addChild(myMovieClip2);
I want to delete them all and I have tried...
removeChild(myText1);
ETC
But this doesn't work.
can anyone help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想从当前对象中删除所有内容,您可以执行以下操作:
如果您的 DisplayObjects 在舞台上,您可以执行以下操作:
If you want to remove everything from the current object, you can do :
If your DisplayObjects are on the stage, you can do :
如果您只想删除这些特定对象,那么您需要将对它们的引用存储在某处。
另一种解决方案是在创建每个对象时填充每个对象的 .name 属性,然后在将来使用该名称来获取对该对象的引用:
然后在稍后的某个时间:
getChildByName 会带来相当多的开销不过,所以重复调用它确实不是一个好主意,或者在当前显示列表很复杂/很深的情况下
If you only want to be able to delete those specific objects, then you'll need to store references to them somewhere.
An alternative solution would be to populate the .name property of each object when you create it, and then use that name at a future time to grab a reference to the object:
And then at some later time:
getChildByName carries quite a bit of overhead though, so it's really not a good idea to call it repeatedly, or in a situation where the current display list is complex/deep
您需要为每个动态创建的对象拥有成员变量,以便您可以在用于创建它们的函数之外引用它们。如果您只需要一个引用将它们从舞台上删除,那么数组会很好用。
You need to have member variables for each of the dynamically created objects so you can reference them outside of the function you used to create them. If you only need a reference to remove them from the stage, an array will work great.