8 Replies Latest reply on Oct 13, 2010 5:26 PM by Flex harUI

    ArrayCollection.reverse();

    Seglespaan

      Hi,

       

      just wondering why the following code reverses the order of my userObj array collection.

       

      trace(dataModel.userObj .source);

      lp_array = new ArrayCollection(dataModel.userObj .source);

      lp_array.source.reverse();

      trace(dataModel.shapes.source);

        • 1. Re: ArrayCollection.reverse();
          Seglespaan Level 1

          sorry should have read

           

           

          trace(dataModel.userObj .source);

          lp_array = new ArrayCollection(dataModel.userObj .source);

          lp_array.source.reverse();

          trace(dataModel.userObj .source);

           

           

          I'm creating lp_array from the source and then reversing the source of lp_array, so why is the userObj source also reversed?

           

          Tim

          • 2. Re: ArrayCollection.reverse();
            Flex harUI Adobe Employee

            The source is referenced, not copied, so you are modifying the same array

            1 person found this helpful
            • 3. Re: ArrayCollection.reverse();
              Seglespaan Level 1

              So how would i copy the source then?

              • 4. Re: ArrayCollection.reverse();
                Flex harUI Adobe Employee

                Slice()

                1 person found this helpful
                • 5. Re: ArrayCollection.reverse();
                  Seglespaan Level 1

                  Thanks harUI

                   

                  Essentially both of my previous questions have been answered perfectly and very precisely, so I'm going to ask one more which might take a little longer to explain. Well 2

                   

                  First off, is it possible to display the tiles in a tile list in reverse order without reversing the source array of the dataprovider?

                   

                  Second, I'm starting to think that its not so here's what I'm trying to do.

                   

                   

                  I have an array collection that populates a tile list. I'm using the tile list as a layers palette similar to that in photoshop.

                   

                  The array collection is made up of various different view models that are added to the stage by the user at runtime.

                   

                  So the application loads and then the user adds a square, a circle and a triangle, because of the order they're added they are stacked / layered in the same order with the square on the bottom and the triangle on the top.

                   

                  So my arraycollection now consists of three objects, and if I use it to populate a tile list, I can see a representation of the three objects in the tile list, but they are in the opposite order from the way they display on screen with the square at the top and the triangle on the bottom.

                   

                  If I drag the square tile from the top to the bottom, this change is reflected on the stage, except the square moves from the bottom to the top.

                   

                  so if I'm correct in not being able to reverse the order of these tiles I'm looking to achieve the following.

                   

                   

                  AC1 is the container for the objects on the stage,

                  I listen for a change to this collection and trigger the following

                   

                  create AC2 and pass in a COPY (using splice) into its constructor when its instantiated,

                  then reverse AC2 source

                   

                  AC2 is used as a dataprovider for my tile list

                  the tiles now show in the same layer order as the stage, with square on the bottom and triangle on top.

                   

                   

                  The bit I'm stuck with now is binding the dragging of a tile to a new layer to the objects on the stage. Is there a quicker / cleaner way than getting the index of the dragged item, the index of where its dropped and then manually re-ordering AC1

                   

                  Cheers

                   

                  Tim

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                  • 6. Re: ArrayCollection.reverse();
                    Flex harUI Adobe Employee

                    In between the AC and the Array is an ArrayList which is assigned as the

                    list property of the AC.  You can swap out the ArrayList for one that will

                    read the source array in reverse order.

                    • 7. Re: ArrayCollection.reverse();
                      Seglespaan Level 1

                      you couldn't give an example of how to do that could you?

                      • 8. Re: ArrayCollection.reverse();
                        Flex harUI Adobe Employee

                        There are examples of custom ArrayLists on my blog:

                        http://blogs.adobe.com/aharui/?s=Ilist

                         

                        Yours will probably need to override getItemAt and return

                        super.getItemAt(length - index - 1)