在 Actionscript 3 中链接两个数组

Linking two arrays in Actionscript 3

对 actionscript 很陌生,

我正在尝试 link 两个数组。基本上我有一个包含 8 个单词的单词数组和一个包含 8 个影片剪辑的影片剪辑数组。我的目标是 link 这两个数组,以便用户必须单击与屏幕上显示的单词相匹配的正确影片剪辑。

非常感谢所有帮助!!

var listAry:Array = [];
var orangeJuice:Object = new Object();
orangeJuice.name= "Orange Juice";
orangeJuice.matchingImage=oj;
listAry[0]=orangeJuice;
////etc etc

给你伙计。希望对你有帮助,有问题尽管问。

另一种方法是使用 Dictionary

var foodionary:Dictionary = new Dictionary();

foodionary["Orange Juice"] = oj;
foodionary["Sandwich"] = sand;
//etc...

for(var key:String in foodionary) {
    trace(key + " matches with " + foodionary[key].id); //assuming your images have ids
}

不过,对于随机访问,您仍然需要一个数组(或 Vector):

function displayword(){

    randomnumber = Math.floor(Math.random() * randomlistword.length);
    trace("random number = " + randomnumber);

    var chosenword = randomlistword[randomnumber];
    randomword.text = chosenword
    randomword.img = foodionary[chosenword];
    randomlistword.splice(randomnumber, 1);
    trace("randomlistword array: " + randomlistword);

}//close displayword function