Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 在x秒后移除一个子对象?AS3_Actionscript 3 - Fatal编程技术网

Actionscript 3 在x秒后移除一个子对象?AS3

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

我想在创建子对象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(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的更多信息,请参阅以下链接:

是的,正如你发布的那样,我发现了……我尝试了完全相同的方法,但我弄错了函数名(添加了一个额外的大写字母):(无论如何,谢谢!