Reputation: 30158
I have an array of movie clips (representing band members) which have various properties, among them them a property which tells where the band member went to after they left their current band. For those who formed a new group, I want to create an array. Within that array, I want to group all the ones that left for the same group into secondary arrays. So, if you had five band members and 2 of them left for group X and 3 left for group Y. What's the best way to do this? This is, roughly, my code:
var newGroupArr:Array = new Array() //this will hold all members leaving for a new group
for (k=0;k<memberClips.length;k++){
if (memberClips[k].outcome == "new"){
//for all groups where memberClips[k].group is the same, create a new array within newGroupArr for those similar members.
}
}
Alternatively I suppose if I could do without a multidimensional array and just loop through all the members and say - for those members whose group is the same, perform this function, with the name of that same group passed as the parameter for the function. I guess the trouble I'm having is identifying who's the same.
Upvotes: 0
Views: 2092
Reputation: 2727
Unless there's a reason why you need to use an array, I'd use a Dictionary, like so
var bands:Dicionary = new Dictionary();
for (k=0;k<memberClips.length;k++){
if(memberClips[k].outcome=="new"){
var newGroup:String = memberClips[k].group;
if(!bands[newGroup]){
bands[newGroup] = new Array();
}
bands[newGroup].push(k);
}
}
Now each array in bands will contain the members that left their previous band
Upvotes: 1
Reputation: 6485
Using AS3, look at http://livedocs.adobe.com/flex/3/html/help.html?content=10_Lists_of_data_5.html
Upvotes: 0