0

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.

This illustration shows the problem I'm having - if John Wetton is clicked, a line should be drawn only for him. But instead, a line is drawn for both he, david cross, and bill bruford, because they are all leaving for a new group. But david cross and bill bruford are actually going to a different group than john, so I need to make sure they are stored as members leaving for a new group, but I also need them grouped by the new band they are leaving for.

3
  • do i understand it right that you need to create a data structure for easy access of: a) list of members by band name and b) list of bands where person played by person name? Commented May 13, 2011 at 20:48
  • not really - it's even simpler than that. I'm drawing a sort of family tree, and I just need to make sure that all the band members leaving for new group A have lines drawn from the old group to the new group, and all band members leaving for new group B have lines drawn from the old group to their new group. Commented May 13, 2011 at 21:09
  • It might help to see how it's displayed. I think I understand how you wish to group them, but I don't see the need for multidimensional arrays. The way I would handle this would be to have a band member class with a history stack. I someone could be in more than one band at once, it might not be as simple as a stack, it could be a simple tree. I'm just saying that for me, the history associates more naturally with the person than with the band. Commented May 14, 2011 at 4:21

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

Using AS3, look at http://livedocs.adobe.com/flex/3/html/help.html?content=10_Lists_of_data_5.html

1 Comment

thanks - yeah I know how to create the array - I just don't know how to create in a manner in which only clips with the same value get pushed to the appropriate secondary array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.