わかりました。indexOfを使用して、これで動作するようにしました。しかし、このコードの下に乱数を付けてコードを投稿しましたが、動作しません。
movieClip_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
var allreadyPicked:Array = [1,2,3,4,5];
var pickedNum:Array = [3,5];
function compareArrays(init_arr:Array, comparing_arr:Array):Array
{
var differenceArray_arr:Array = new Array();
for each (var id_obj:Object in init_arr)
{
if (comparing_arr.indexOf(id_obj) >= 0)
{
differenceArray_arr.push(id_obj);
}
}
return differenceArray_arr;
}
trace("Matched Number " + compareArrays(allreadyPicked, pickedNum));
}
しかし、乱数コードを追加すると、アイデアが機能しないようです。
movieClip_1.addEventListener(MouseEvent.CLICK, clicked);
function clicked(event:MouseEvent):void
{
//
var allreadyPicked:Array = [1,5];
//
var numPool:Array = [1,2,3,4,5,6];
var numPicked:Array = [];
var randomCount:Number = 1;
var r:Number;
for (var i = 0; i < randomCount; i++)
{
r = Math.floor(Math.random() * numPool.length);
numPicked[numPicked.length] = numPool.splice(r,1);
}
trace("Number Picked " + numPicked);
ranNum.text = String(numPicked);
function compareArrays(init_arr:Array, comparing_arr:Array):Array
{
var differenceArray_arr:Array = new Array();
for each (var id_obj:Object in init_arr)
{
if (comparing_arr.indexOf(id_obj) >= 0)
{
differenceArray_arr.push(id_obj);
}
}
return differenceArray_arr;
}
trace("Matched " + compareArrays(allreadyPicked, numPicked));