PDA

View Full Version : [Arrays][Flash] Is it possible to search?



Steyene
03-19-2008, 05:31 AM
Hey I was just mucking about with arrays in Flash, and am wondering if it is possible to loop through each of the "draws" and compare data to another variable?

Here is what I have so far

var myChest = new Array();
_root.submission.onPress = function(){
var imput = new Array(_root.imput.text);
myChest = myChest.concat(imput);
}I was wondering if I should use a for loop, but every time I do that, I get a infinite loop.

Here is the .swf
height = 400 width = 550
Click and type on the blue rectangle, then click the black one.

As I want to find a way to check if the submitter has already submitted that string, and if they have insert the string "Duplication" instead of what they have typed

darkcampainger
03-19-2008, 03:58 PM
I was wondering if I should use a for loop, but every time I do that, I get a infinite loop.

A for() loop is the way to go. There should be no reason it's turning into an infinite loop if you're handling it right. Here's an example of searching an array:




var awesomeWords:Array = Array("bodacious", "discombobulated", "zebra");

_global.search_array = function (A:Array,S):Boolean {
for(var i in A) {
if(A[i]==S) {
return true;
}
}
}

if(search_array(_root.awesomeWords,"monotony")) {
trace("monotony is an awesome word.");
}
else {
trace("monotony is not an awesome word.");
}

if(search_array(_root.awesomeWords,"discombobulated")) {
trace("discombobulated is an awesome word.");
}
else {
trace("discombobulated is not an awesome word.");
}




Good luck!

Steyene
03-19-2008, 11:40 PM
So is "search_array" a actual command?

darkcampainger
03-20-2008, 01:14 PM
So is "search_array" a actual command?

No. But if you add that script to a frame, you can call it anywhere. I wrote it so it could be easily integrated into the system you described. All you need is an if() statement to decide if it's a duplicate or not.

Steyene
03-20-2008, 11:00 PM
Right lol, I missed the fact that you made search_array >_>
Thanks :D