我想在创建子项后删除子项x秒。我怎么能这样做?
子项是在函数内创建的。
基本上就是这样......
function makechild() {
addChild(thechild);
thechild.x=240;
thechild.y=330;
// what should go here? so it deletes after x seconds?
}
答案 0 :(得分:1)
通过flash.utils.setTimeout()使用一次性计时器,如下所示:
setTimeout(dropChild,seconds*1000);
...
function dropChild():void {
removeChild(thechild);
}
答案 1 :(得分:0)
使用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文档中获取有关Timer类的更多详细信息。有关Timer类与setInterval的更多信息,请参阅以下链接: http://blogs.adobe.com/pdehaan/2006/07/using_the_timer_class_in_actio.html