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
Arrays 如何删除ActionScript 3.0中由数组创建的子级_Arrays_Actionscript 3_Removechild - Fatal编程技术网

Arrays 如何删除ActionScript 3.0中由数组创建的子级

Arrays 如何删除ActionScript 3.0中由数组创建的子级,arrays,actionscript-3,removechild,Arrays,Actionscript 3,Removechild,在我的一个帧中,我放置了一个movieclip数组,其中包含movieclip显示的随机帧。将movieclips与特定帧放置在一起后,它将从阵列中拼接。在第45帧,我想摆脱创建的实例,但我尝试使用cats.removeChild或其变体的所有操作似乎都不起作用。有人知道如何摆脱创建的实例吗 function Codetest():void { var cardlist:Array = new Array(); for(var i:uint=0;i<

在我的一个帧中,我放置了一个movieclip数组,其中包含movieclip显示的随机帧。将movieclips与特定帧放置在一起后,它将从阵列中拼接。在第45帧,我想摆脱创建的实例,但我尝试使用cats.removeChild或其变体的所有操作似乎都不起作用。有人知道如何摆脱创建的实例吗

    function Codetest():void {
        var cardlist:Array = new Array();
        for(var i:uint=0;i<4*1;i++) {
            cardlist.push(i);
        }

        for(var x:uint=0;x<4;x++) {
            for(var y:uint=0;y<1;y++) {
                var c:cats = new cats();
                c.x = x*450+105;
                c.y = y*550+300;
                var r:uint = Math.floor(Math.random()*cardlist.length);
                c.cardface = cardlist[r];
                cardlist.splice(r,1);
                c.gotoAndStop(c.cardface+1);

                addChild(c); // show the card
            }

        }
函数Codetest():void{
var cardlist:Array=new Array();

for(var i:uint=0;iReferencecats似乎是一个类,因此您无法通过cats类删除cats的实例(除非编码为这样)。您需要做的是清理添加这些子级的容器

实施:

function clear():void
{
    while (numChildren > 0) removeChildAt(0);
}
用法:

clear();

引用cats似乎是一个类,因此您无法通过cats类删除cats的实例(除非编码为这样)。您需要做的是清理添加这些子项的容器

实施:

function clear():void
{
    while (numChildren > 0) removeChildAt(0);
}
用法:

clear();

您需要以某种方式存储创建的movieclips,例如在另一个数组中:

// this variable should be outside of your function so it will be still available at frame 45. Variables declared inside the function are only accessible from that function
var cardsArray:Array = []; // same as new Array() but a bit faster :)

function Codetest():void {
    var cardlist:Array = new Array();
    for(var i:uint=0;i<4*1;i++) {
        cardlist.push(i);
    }

    for(var x:uint=0;x<4;x++) {
        for(var y:uint=0;y<1;y++) {
            var c:cats = new cats();
            c.x = x*450+105;
            c.y = y*550+300;
            var r:uint = Math.floor(Math.random()*cardlist.length);
            c.cardface = cardlist[r];
            cardlist.splice(r,1);
            c.gotoAndStop(c.cardface+1);

            addChild(c); // show the card

            // push the new card movieclip into our fancy array
            cardsArray.push(c);
        }
    }
}
//此变量应该在函数外部,因此在第45帧时仍然可用。函数内部声明的变量只能从该函数访问
var cardsArray:Array=[];//与new Array()相同,但速度稍快:)
函数Codetest():void{
var cardlist:Array=new Array();

对于(var i:uint=0;i您需要以某种方式存储您创建的movieclips,例如在另一个数组中:

// this variable should be outside of your function so it will be still available at frame 45. Variables declared inside the function are only accessible from that function
var cardsArray:Array = []; // same as new Array() but a bit faster :)

function Codetest():void {
    var cardlist:Array = new Array();
    for(var i:uint=0;i<4*1;i++) {
        cardlist.push(i);
    }

    for(var x:uint=0;x<4;x++) {
        for(var y:uint=0;y<1;y++) {
            var c:cats = new cats();
            c.x = x*450+105;
            c.y = y*550+300;
            var r:uint = Math.floor(Math.random()*cardlist.length);
            c.cardface = cardlist[r];
            cardlist.splice(r,1);
            c.gotoAndStop(c.cardface+1);

            addChild(c); // show the card

            // push the new card movieclip into our fancy array
            cardsArray.push(c);
        }
    }
}
//此变量应该在函数外部,因此在第45帧时仍然可用。函数内部声明的变量只能从该函数访问
var cardsArray:Array=[];//与new Array()相同,但速度稍快:)
函数Codetest():void{
var cardlist:Array=new Array();

for(var i:uint=0;iAwesome!这非常好用!感谢您的支持(Y)太棒了!这非常好用!感谢您的支持(Y)或者,为了让它变得非常简单,请使用内置的
removeChildren()
方法添加到flash player 11中,虽然我猜OP只希望清除猫,在这种情况下,类似的方法会很好地工作,但在删除之前使用
if(getChildAt(I)是猫)
条件。@badfeengabout这是肯定的,可能是。或者,为了让它更简单,使用内置的
removeChildren()
方法添加到flash player 11中,虽然我猜OP只希望清除猫,在这种情况下,类似于此的方法会很好地工作,但在删除之前,如果(getChildAt(I)是猫)
条件。@badfeengabout这是肯定的,可能是这样。