Hi,
Sorry for the cross-post, this post was a mistake, but your reply is
still greatly appreciated.
CK
On Apr 21, 2006, at 8:23 AM, Merrill, Jason wrote:
Chris, I see you posted the same question on Flashnewbies too (tsk
tsk)
- so I will reply here as well:
So as an alternative, how about using object arrays instead?
Personally, I like that so I can use dot syntax to get my data.
Multidimensional arrays have there uses, but they can also get real
messy and confusing real easy. Objects with a hierarchy of properties
binds related data together.
var people:Array = [
{firstname:"Chris", lastname:"Kennon", age:39, location:"CA"},
{firstname:"Alice", lastname:"Miller", age:24, location:"WA"},
{firstname:"Margie", lastname:"Johnson", age:36, location:"MI"}
];
//Then, to acesss:
trace(people[0].firstname) //traces "Chris"
trace(people[1].firstname)//traces "Alice"
trace(people[1].age) //traces "24"
trace(people[2].location) //traces "MI"
...etc.
This way, the data sets stay associated with themselves. You can
easily loop through the data to find all the people who have the last
name of "Miller" and live in CA that way. I.e. to find all the
names of
people who live in Michigan:
//data set:
var people:Array = [
{firstname:"Chris", lastname:"Kennon", age:39, location:"CA"},
{firstname:"Alice", lastname:"Miller", age:24, location:"WA"},
{firstname:"Lucy", lastname:"Adams", age:36, location:"MI"},
{firstname:"George", lastname:"Miller", age:24, location:"AZ"},
{firstname:"Margie", lastname:"Johnson", age:55, location:"MI"},
{firstname:"Jim", lastname:"Johnson", age:31, location:"MI"}
];
//find index function:
function findIndex(dataset:Array, findProperty:String,
findString:String):Array{
var resultsArray:Array = new Array();
for(var i=0; i<dataset.length; i++){
if(dataset[i][findProperty] == findString){
resultsArray.push(i);
}
}
return resultsArray;
}
//find indexes of people in Michigan:
var MichiganPeople:Array = findIndex(people, "location", "MI");
//show names of people in Michigan:
for(var i=0; i<MichiganPeople.length; i++){
trace(people[MichiganPeople[i]].firstname+"
"+people[MichiganPeople[i]].lastname);
};
Hope that helps,
Jason Merrill | E-Learning Solutions | icfconsulting.com
NOTICE:
This message is for the designated recipient only and may contain
privileged or confidential information. If you have received it in
error, please notify the sender immediately and delete the
original. Any other use of this e-mail by you is prohibited.
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com