  | |  | Re: Find stuff in Flash array? | Re: Find stuff in Flash array? 2003-12-03 - By Hubert Spall
Back Looping throught the array is the only way to do it. This is the case in any language, though some (e.g. lingo) include wrapper functions which hide the fact that this is what is happening. However, you will find lingo functions such as List.getOne() to be slow too when dealing with a large list, they aren't very much more efficent than looping (though there will be some optimisations made by writing the wrapper in a low level language rather than e.g. actionscript). Flash will be slower still, but only because it generally is, not because it has to loop.
If your data set is sorted this will help narrow the search - look into Array.sort() and Array.sortOn() - you could add custom array methods to search only particular parts of a sorted list. Or you could break your data into categories, and only search the relevent categories, not the whole list.
But if your array is simply a flat list, there is no logical way to retrieve specific items other than checking one by one for a match.
Hubert
Quoting Daniel Isenhower <jml@(protected)>:
> > Does anyone here have knowlege of Flash arrays? > > Say I've got an Array(1,3,5,7,11). How can I find out if 3 is in the > array? > > ...and just to clarify what I've already been through: > > I obviously can't access it like this: > > var someNumbers = Array(1,3,5,7,11); > var lookingFor = 3; > trace(someNumbers[lookingFor]); > > ...becuase that would return 7. > I've also tried it like this: > > var someNumbers = Array(1,3,5,7,11); > var lookingFor = 3; > trace(someNumbers[String(lookingFor)]); > > ...and it returns "undefined". Not that I was expecting that to work > anyway, but I'm getting desparate. Is there no other way other than looping > through the entire array? > > var someNumbers = Array(1,3,5,7,11); > var lookingFor = 3; > for (var i in someNumbers) { > if (someNumbers[i] == lookingFor) { > trace("i've found it the inefficient way :-/"); > } > } > > ...the array could potentially be very big. I would think that would slow > down my project quite a bit eventually. > > Surely there's another way? I've looked through the AS help and on > macromedia.com, but to no avail :( > > -Daniel > www.triinfinite.net > www.freewebhome.com > www.fervorstudios.com > > __ ____ ____ ____ ____ ____ ____ ____ ____ ____ > dirGames-L mailing list - dirGames-L@(protected) > http://nuttybar.drama.uga.edu/mailman/listinfo/dirgames-l > > __ ____ ____ ____ ____ ____ ____ ____ ____ ____ dirGames-L mailing list - dirGames-L@(protected) http://nuttybar.drama.uga.edu/mailman/listinfo/dirgames-l
Earn $52 per hosting referral at Lunarpages.
|
|
 |