本文介绍了如何使 MovieClip 在 AS3 中自行删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

AS3 中 removeMovieClip() 的等价物是什么?

What is the equivalent to removeMovieClip() in AS3?

显然很多人都有同样的问题:
堆栈溢出:

Apparently many have the same question:
StackOverflow:

  1. 如何在 as3 中完全删除影片剪辑
  2. 删除影片剪辑 as3
  3. 如何删除 childmovieclip 并添加到新的父级影片剪辑

其他:

  1. 在 AS3 中删除MovieClip(this)?
  2. 销毁/删除影片剪辑???
  3. 删除影片剪辑

但对我来说,他们的解决方案似乎都不起作用:

But none of their solutions seem to work, for me:

我正在使用 AS3 开发 flash CS4:

Im working on flash CS4 with AS3:

我有一个非常简单的电影,只有一个名为 click 的按钮.按下按钮后,会创建一个 coin 的新实例:

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
}

它可能不是最好的代码,但它运行良好.现在,硬币 MovieClip 应该显示一个小动画并自行移除.在旧的 AS2 中,我会添加:

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()

在动画的最后一帧.但这在 AS3 中不存在.
我试过了,没有成功:

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'

解决方案?

谢谢,

推荐答案

this.parent.removeChild(this);

这个应该可以工作;这是我使用的.我切换到 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:

import flash.display.*

在移除之前,您还应该移除其上的事件侦听器.

You should also remove the event listener on it before removing it.

这篇关于如何使 MovieClip 在 AS3 中自行删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:40