This article shows how you can easily check if a specific value already exists in an Array in Actionscript 3.
Actionscript:
Actionscript:
-
var doesExist:Boolean;
-
var rndInt:int;
-
var rndArr:Array = new Array();
-
-
var timer:Timer = new Timer(200, 15);
-
timer.addEventListener(TimerEvent.TIMER, fillArray);
-
timer.start();
-
-
function fillArray(event:TimerEvent):void {
-
rndInt = Math.floor(Math.random() * 15);
-
doesExist = rndArr.every(checkExisting);
-
doesExist ? rndArr.push(rndInt) : fillArray(null);
-
trace(rndArr);
-
}
-
-
function checkExisting(element:*, index:int, arr:Array):Boolean {
-
return (element != rndInt);
-
}



September 2nd, 2009
Marvin Blase
Posted in
Tags:
[...] [...]
[...] Check if value exists in Array [...]
Why not just use the "indexOf" method of an Array? Returns -1 if a value doesn't exist in the array, or the index position if it does.
I can't seem to fully load this site from my smartphone!!!!
hello how are you lyrics elo