如何在AS3中初始化二维类型Vector?
现在我只能这样做了:
private var _mainArray : Array = new Array( MyConst.DIMENTION );
public function MyArray()
{
for ( var i : int = 0; i < MyConst.DIMENTION; i++ ) {
_mainArray[ i ] = new Vector.<int>( MyConst.DIMENTION );
}
}
...
_mainArray[ i ][ j ] = 0;
答案 0 :(得分:14)
你拥有的是一个int of Vector数组。你想要的是一个矢量的矢量。
因此,您的“外部”Vector必须声明包含Vector.<int>
这样的东西(当然你可以使用for循环):
var v:Vector.<Vector.<int>> = new Vector.<Vector.<int>>(2);
v[0] = new Vector.<int>(2);
v[1] = new Vector.<int>(2);
v[0][0] = 0;
v[0][1] = 1;
v[1][0] = 2;
v[1][1] = 3;
trace(v);
答案 1 :(得分:-1)
private var _labelsRefs:Vector.<Vector.<Object>> = new Vector.<Vector.<Object>>( );
private var _labelsFrRefs:Vector.<Object> = new Vector.<Object>( );
private var _labelsEnRefs:Vector.<Object> = new Vector.<Object>( );
_labelsRefs [ _labelsRefs.length ] = _labelsFrRefs;
_labelsRefs [ _labelsRefs.length ] = _labelsEnRefs;
如果需要,您可以添加10个附加项目
_labelsFrRefs [ _labelsFrRefs.length ] = [ _label.@key, _label.@xml ];
然后你可以搜索_labelsRefs:Vector
public function searchKeyXml ( langue:String, key:String, val:int ):String
searchKeyXml ( "fr", "three", 1 ); medias/xmls/fr/homepage1.xml
searchKeyXml ( "en", "three", 1 ); medias/xmls/en/homepage1.xml