如何在Actionscript中定义Java的Object [] someObject = new Object [10]

时间:2012-08-25 18:00:51

标签: arrays actionscript

我有一个名为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?

2 个答案:

答案 0 :(得分:0)

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

private var vector:Vector.<SomeComponent> = new Vector.<SomeComponent>(10);
private var anotherOne:Vector.<Number> = new Vector.<Number>;

答案 1 :(得分:0)

谢谢你的回答。我找到了可能是另一个例子的东西。 只需定义一个像

这样的数组
var myArray:Array=new Array();
之后

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

myArray[0]=new Component(); //Here Component is the class which I defined and showed in my original question.