Actionscript 3 在x秒后移除一个子对象?AS3
我想在创建子对象x秒后将其删除。我该怎么做 子项是在函数内部创建的 基本上是这样的Actionscript 3 在x秒后移除一个子对象?AS3,actionscript-3,Actionscript 3,我想在创建子对象x秒后将其删除。我该怎么做 子项是在函数内部创建的 基本上是这样的 function makechild() { addChild(thechild); thechild.x=240; thechild.y=330; // what should go here? so it deletes after x seconds? } 通过flash.utils.setTimeout()使用一次性计时器,如下所示: setTimeout(dropChi
function makechild() {
addChild(thechild);
thechild.x=240;
thechild.y=330;
// what should go here? so it deletes after x seconds?
}
通过flash.utils.setTimeout()使用一次性计时器,如下所示:
setTimeout(dropChild,seconds*1000);
...
function dropChild():void {
removeChild(thechild);
}
对于Actionscript 2,您将使用setInterval。但是,Actionscript 3的方法是使用Timer类,如下所示:
function makechild() {
addChild(thechild);
thechild.x=240;
thechild.y=330;
// add a timer to "thechild" that will trigger it to be deleted
thechild.selfdestruct:Timer = new Timer(1000, 1); // 1 second
thechild.selfdestruct.addEventListener(TimerEvent.TIMER, deleteobject);
thechild.selfdestruct.start();
}
function deleteobject(event:TimerEvent):void {
// delete the child object, below is one example
this.parent.removeChildAt(0);
}
您可以从Actionscript文档中获得更多关于计时器类的详细信息。有关计时器类与setInterval的更多信息,请参阅以下链接:
是的,正如你发布的那样,我发现了……我尝试了完全相同的方法,但我弄错了函数名(添加了一个额外的大写字母):(无论如何,谢谢!