7 Replies Latest reply: Apr 16, 2012 6:17 AM by Ned Murphy RSS

    Movieclip Sort

    A.kameshwaran Community Member

      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.

        • 1. Re: Movieclip Sort
          Ned Murphy MVP

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

          • 2. Re: Movieclip Sort
            A.kameshwaran Community Member

            I am having a set of pages( like the letter pad with same size) that i have created using separate movieclip. I am placing the set of bitmap images in those page template in the sequence which i got as input. User has the option to move the image. Once he is done with that i need to give the reference to next process like which image is placed in which template. But i should not give them in the input sequence. I have to give them in the template sequence. So while placing the image i am giving the template number to each and every movieclip. Also, i am doing the same while moving the image. now i need to give it in the template sequence. Thats y i am asking this option.

             

            kindly let me know if still i am not clear.

            • 3. Re: Movieclip Sort
              Ned Murphy MVP

              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)
              }

              • 4. Re: Movieclip Sort
                A.kameshwaran Community Member

                mc1 = _root.createEmptyMovieClip("mc1",_root.getNextHighestDepth());

                mc2 = _root.createEmptyMovieClip("mc2",_root.getNextHighestDepth());

                mc3 = _root.createEmptyMovieClip("mc3",_root.getNextHighestDepth());

                mc4 = _root.createEmptyMovieClip("mc4",_root.getNextHighestDepth());

                mc5 = _root.createEmptyMovieClip("mc5",_root.getNextHighestDepth());

                 

                mc1.val = 3;

                mc2.val = 2;

                mc3.val = 1;

                mc4.val = 4;

                mc5.val = 5;

                 

                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});

                 

                trace(mcs)

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

                 

                for(i=0;i<sortedMCs.length;i++){

                    trace(sortedMCs[i].mc)

                }

                 

                 

                When i try with the above code it is not working. kindly let me know what is wrong in the above code.

                • 5. Re: Movieclip Sort
                  Ned Murphy MVP

                  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

                  • 6. Re: Movieclip Sort
                    A.kameshwaran Community Member

                    It is working fine. Thanks for the information and for the valuable time.

                    • 7. Re: Movieclip Sort
                      Ned Murphy MVP

                      You're welcome