Mailing List
Home
Flash Pro
Extending Flash
Flash Macromedia Developer
Subjects
Firework Effect
setInterval bug identified and fixed
setInterval bug identified and fixed
ScrollPane component doesn 't auto update
Help: MX 2004 How to script a print button to print the entire sli
Event Dispatcher between classes
memory management removeMovieClip /
MX2004 Dataset itemClassName
Order of events per frame
XML to Object help
Textfield prototype question
Flash and QuickTime VR
Reading and displaying RSS feeds in Flash MX
Flash MX 2004 Sucks
AW: [Flashcoders] Switch/Case vs If/else
AW: [Flashcoders] Switch/Case vs If/else
Flash Interface with 10mb xml file
Web Service Results
Listener Object 's best practice
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
Recursive search function

Recursive search function

2004-02-17       - By Richard

 Back
Reply:     1     2     3     4     5     6     7  

Hello all,

I 'm trying to write a method for the Array class that allows you to search
its structure for a value, be it string or int etc and return the Array
index of any object that contains this value (or even a child object of that
object).
A typical structure may be:

"theArray " contains 6 Objects, each Object contains 4 String values.

Here 's how far I got (always returns 0 :/):

// Search for string in properties of an array of objects, return array
index
Array.prototype.searchForValue = function(theValue) {
trace( "Searching for " + theValue);
var pos = -1;

for (var i in this) {
pos++;
if (this[i] == theValue) {
return pos;
} else if(Array.searchForValue.apply(i, theValue) > -1) {
return pos;
}
}
return -1; // -1 if not found
}

Anyone have any idea how to get this to work correctly? Or another example
of how to do this?

Thanks so much,
Rich

=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:104428
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)