Skip navigation
A.kameshwaran
Currently Being Moderated

Movieclip Sort

Apr 12, 2012 11:59 PM

Hi

 

I am having set of movieclips, say  

 

mc1,mc2,mc3,mc4 and mc5

 

I do have the properties for these movieclips as below

 

mc1.val = 4

mc2.val = 7

mc3.val = 3

mc4.val = 2

mc5.val = 7

 

I need to know how can i sort these movieclips in ascending order like below based on the variable val .

 

mc4 , mc3 , mc1 , mc2 , mc5

 

 

Regards,

Kameshwaran A.

 
Replies
  • Currently Being Moderated
    Apr 13, 2012 5:02 AM   in reply to A.kameshwaran

    What kind of set are they contained in such that you would have reason to sort them?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 13, 2012 6:23 AM   in reply to A.kameshwaran

    What you can do is place them into an array as objects, each defining the mc and its val property, and then use the Array.sortOn method...

     

    mc1.val = 4;
    mc2.val = 7;
    mc3.val = 3;
    mc4.val = 2;
    mc5.val = 7;

     

    var mcs:Array = new Array({mc:mc1, val:mc1.val},{mc:mc2, val:mc2.val},{mc:mc3, val:mc3.val},{mc:mc4, val:mc4.val},{mc:mc5, val:mc5.val});

     

    var sortedMCs:Array = mcs.sortOn("val", Array.NUMERIC);

     

    for(i=0;i<sortedMCs.length;i++){
        trace(sortedMCs[i].mc)
    }

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 4:33 AM   in reply to A.kameshwaran

    The code you show is working, though you might be misreading the results due to the way they resemble the order of the values you started with.  You are tracing the mcs, not the val properties

     

    The original array has them ordered mc1 2 3 4 5, while the sorted one has 3 2 1 4 5

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 6:17 AM   in reply to A.kameshwaran

    You're welcome

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points