在Actionscript 3中链接两个数组

时间:2022-10-11 21:18:35

Very new to actionscript,

对于动作脚本来说很新

Im trying to link two arrays. Basically I have a word array of 8 words and I have a movie clip array of 8 movieclips. My aim is to link the two arrays so that the user must click the right movie clip that matches the word that was displayed on screen.

我试图链接两个数组。基本上我有一个8字的单词数组,我有一个8个动画片段的影片剪辑阵列。我的目标是链接两个数组,以便用户必须单击与屏幕上显示的单词匹配的右侧影片剪辑。

All help is greatly appreciated!!

非常感谢所有帮助!!

2 个解决方案

#1


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

There you go buddy. Hope that helps if you have any questions just ask.

你去哥们。如果您有任何问题,希望有所帮助。

#2


Another way to do this is with a 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
}

For random access, though, you'll still need an array (or a Vector):

但是,对于随机访问,您仍然需要一个数组(或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

#1


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

There you go buddy. Hope that helps if you have any questions just ask.

你去哥们。如果您有任何问题,希望有所帮助。

#2


Another way to do this is with a 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
}

For random access, though, you'll still need an array (or a Vector):

但是,对于随机访问,您仍然需要一个数组(或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