-1

我有一个名为 Component 的类,它有这样的代码

class Component {

var ID:String;
var typical:String;
var connection:String;
var temperature:String;
var voltage:String;

var visibility:Boolean = true;

public function Component(type:String, temperature:String, connection:String,        voltage:String) {


    this.typical = type;
    this.temperature = temperature;
    this.connection = connection;
    this.voltage = voltage;

}

public function setVisibility(b:Boolean):Void {

    visibility = b;

}

}

我想创建这个类的数组实例,就像在 java 中一样(如 Component[] someComponent = new Component[10]) 我如何定义这是 Actionscript?

4

2 回答 2

0

感谢你的回答。我发现了一些可能是另一个例子的东西。只需定义一个数组

var myArray:Array=new Array();

之后将数组的每个元素定义为另一个对象,例如

myArray[0]=new Component(); //Here Component is the class which I defined and showed in my original question.
于 2012-09-03T12:49:05.953 回答
0

在 Flash Player 10 中,Adobe 添加了Vector类。这是您正在寻找的类型化数组。您可以制作这样的矢量:

private var vector:Vector.<SomeComponent> = new Vector.<SomeComponent>(10);
private var anotherOne:Vector.<Number> = new Vector.<Number>;
于 2012-08-25T18:54:34.127 回答