2011-02-03 88 views
0

我有一個名爲twoDArray嵌套數組組成的類。不能參考數組類

public class TestArray 
    { 

    public function TestArray() { 

    var twoDArray:Array = new Array(new Array("one","two"), new Array("three", "four")); 
    } 

    } 

我有另一個類試圖製作一個類型爲TestArray的變量。

var OrbArray:TestArray = new TestArray(); 

我想我可以引用OrbArray例如使用trace(OrbArray [0] [0]);給我輸出我期待的「一」。當我嘗試這個時,我得到了ReferenceError:錯誤#1069:在com.orbclasses.TestArray上找不到屬性0,並且沒有默認值。最受讚賞的幫助。

回答

0

在你TestArray類:

public class TestArray 
{ 
    public var twoDArray:Array = null; 

    public function TestArray() 
    { 
    twoDArray = new Array(new Array("one", "two"), new Array("three", "four")); 
    } 
} 

注:twoDArray是公開訪問。

現在,當你要訪問它:

var testArray:TestArray = new TestArray(); 
trace("output:", testArray.twoDArray[0][0]); 

即您嘗試訪問屬於testArray財產twoDArray

如果您因爲某種原因想要做testArray[0][0],您也可以這樣做,但爲此您必須查看flash.utils.Proxy類。

1
public dynamic class TestArray extends Array 
{ 

    public function TestArray() 
    { 
    push(new Array("one", "two"), new Array("three", "four")); 
    } 
}