Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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 在as3中将对象放入数组_Arrays_Actionscript 3 - Fatal编程技术网

Arrays 在as3中将对象放入数组

Arrays 在as3中将对象放入数组,arrays,actionscript-3,Arrays,Actionscript 3,因此,我尝试使用for循环创建一行10个按钮,每次运行时创建一个新按钮,每次更改x值。然而,每次创建一个按钮时,我都希望它被放入一个特定的数组中,以便以后我可以引用一个特定的按钮。但是,我不知道如何将对象放入数组中。有可能这样做吗?这是我目前掌握的代码: 包装{ import flash.display.MovieClip; import flash.events.MouseEvent; public class backgound extends MovieClip { var b

因此,我尝试使用for循环创建一行10个按钮,每次运行时创建一个新按钮,每次更改x值。然而,每次创建一个按钮时,我都希望它被放入一个特定的数组中,以便以后我可以引用一个特定的按钮。但是,我不知道如何将对象放入数组中。有可能这样做吗?这是我目前掌握的代码:

包装{

import flash.display.MovieClip;
import flash.events.MouseEvent;

public class backgound extends MovieClip {

    var btnx = 30;
    var btny= 20;
    var row1:Array = [];

    public function backgound() {
        // constructor code
        var continueBtn:Button;
        for(var i=0; i < 10; i++)
        {
            continueBtn = new Button();

            continueBtn.x = btnx;
            continueBtn.y = 100;
            continueBtn.width = 30;
            continueBtn.height = 20;
            continueBtn.border = true;
            continueBtn.visible = true;
            continueBtn.label = "Continue";
            addChild(continueBtn);
            btnx += 30;
        }



    }
}
}在您的循环中:

myArray.push(continueBtn);
或者在您的循环中:

continueBtn =myArray[i]= new Button();  
或者其他很多方式

现在,您可以访问您的按钮:

 myArray[3]// gets the 4th item in your array
我只是想知道,这就是你想要的吗


I H☺这有帮助

是的,这有助于堆谢谢,是的,我还想问你一件事对不起,我之前没有考虑过,如果我想让这个多维数组中的所有东西都是第1行[0],我该怎么做呢?要修改另一个数组中更深的数组,你应该使用更多的括号:myArray[0][2]。在myArray的第一个索引处获取或设置数组的第三个索引。