Actionscript 3 创建以数组作为值的关联数组
在cs4中,我试图创建一个关联数组,其中的值是数组。这些数组只有两个元素,我想这样调用这两个元素中的一个:Actionscript 3 创建以数组作为值的关联数组,actionscript-3,flash,flash-cs4,Actionscript 3,Flash,Flash Cs4,在cs4中,我试图创建一个关联数组,其中的值是数组。这些数组只有两个元素,我想这样调用这两个元素中的一个: var array1:Array = [5, "Example String"] var array2:Array = [7, "Example String 2"] var associativeArray:Object = {a1:array1, a2:array2} trace(associativeArray[a1[0]]) // Print out the value of t
var array1:Array = [5, "Example String"]
var array2:Array = [7, "Example String 2"]
var associativeArray:Object = {a1:array1, a2:array2}
trace(associativeArray[a1[0]]) // Print out the value of the first element of the first array. Should print out 5
但是,这不会打印出第一个元素。奇怪的是,如果省略“[0]”,程序会这样打印整个数组:“5,示例字符串”
如何从关联数组内的数组中只打印一个元素。方括号访问运算符中的参数序列错误[]。您需要使用正确的符号:
// The whole collection.
trace(associativeArray);
// The collection element, square bracket notation.
// The key MUST be a String.
trace(associativeArray["a1"]);
// The collection element, dot notation.
trace(associativeArray.a1);
// Access the element of collection element.
trace(associativeArray["a1"][0]);
trace(associativeArray.a1[0]);
// WRONG. Access non-existent element of the collection.
trace(associativeArray[a1[0]]);
trace(associativeArray["a1"[0]]);