AS3 中的 removeMovieClip()
等效项是什么?
显然很多人都有同样的问题:
StackOverflow:
- 如何完全删除as3中的影片剪辑
- 删除影片剪辑 as3
- 如何删除 childmovieclip 并添加到新的父 movieclip
其他:
- 在 AS3 中删除MovieClip(this)?
- 销毁/删除影片剪辑???
- 删除影片剪辑
但他们的解决方案似乎都不起作用,对我来说:
我正在使用 AS3 开发 flash CS4:
我有一个非常带有一个名为单击的按钮的简单电影。按下按钮后,就会创建一个新的coin实例:
this.click.addEventListener(MouseEvent.CLICK,justclick);
function justclick(e:MouseEvent){
var money=new coin
this.addChild(money)
money.x=e.stageX
money.y=e.stageY
}
它可能不是最好的代码,但它工作得很好。现在,硬币 MovieClip 应该显示一个小动画并自行移除。在旧的 AS2 中,我会添加:
this.removeMovieClip()
在动画的最后一帧中。但这在 AS3 中不存在。
我已经尝试过,但没有成功:
this.parent.removeChild(this) // 'Cannot access a property or method of nullobject reference'...
this.removeMovieClip() // 'removeMovieClip is not a function'
removeMovieClip(this) //'call to possibly undefined method removeMovieClip'
unloadMovie(this)//'call to possibly undefined method removeMovieClip'
解决方案?
谢谢,
What is the equivalent to removeMovieClip()
in AS3?
Apparently many have the same question:
StackOverflow:
- How to completely remove a movieclip in as3
- Remove movie clip as3
- How to remove childmovieclip and add to new parent movieclip
Others:
- removeMovieClip(this) in AS3?
- Destroy/Delete a Movieclip???
- Remove movie clip
But none of their solutions seem to work, for me:
Im working on flash CS4 with AS3:
I have a very simple movie with a single button called click. On pressing the button, a new instance of coin is created:
this.click.addEventListener(MouseEvent.CLICK,justclick);
function justclick(e:MouseEvent){
var money=new coin
this.addChild(money)
money.x=e.stageX
money.y=e.stageY
}
It might not be the best code, but it works fine. Now, the coin MovieClip is supposed to show a small animation and remove itself. In good old AS2 I would have added:
this.removeMovieClip()
in the last frame of the animation. But this doesn't exist in AS3.
I have tried, without success:
this.parent.removeChild(this) // 'Cannot access a property or method of nullobject reference'...
this.removeMovieClip() // 'removeMovieClip is not a function'
removeMovieClip(this) //'call to possibly undefined method removeMovieClip'
unloadMovie(this)//'call to possibly undefined method removeMovieClip'
Solutions?
Thanks,
发布评论
评论(5)
这个应该可以工作;这就是我用的。当我切换到 AS3 时遇到的一个问题是,有时它不会作为子项添加,因此您可能需要检查一下。如果您还没有导入 flash.display,则还必须将其放在顶部:
您还应该在删除它之前删除其上的事件侦听器。
This one should be working; it's what I use. One problem I had when I switched to AS3 is that sometimes it wouldn't be added as a child right, so you might want to check that. You also have to import flash.display via putting this at the top if you're not already:
You should also remove the event listener on it before removing it.
如果您的动画在第 20 帧结束。
注意:使用 19 是因为 Flash 从零 (0) 开始计数帧,类似于数组索引。
If your animation is ending on frame 20.
note: using 19 because flash count frames from zero(0) similar to array index.
始终确保那些自动删除的影片剪辑可以被垃圾收集。
此解决方案从加载的 swf 库符号中擦除了我的所有实例:
Always ensure that those self removing movieclips can get garbage collected.
This solution wiped away all my instances from a loaded swf's library symbol:
我在 MovieClip 末尾的额外空白关键帧中使用它,该关键帧应该自行删除:
发现它是正确且最佳的解决方案。
I use, in an extra blank keyframe at the end of the MovieClip which should remove itself:
Found it to be the proper and best solution.