5 Replies Latest reply on Jul 23, 2011 11:08 PM by Flex harUI

    Objects in Array / ArrayCollection with FlowLayout

    kid electric

      I am pretty baffled by what is happening here:


      I am attempting to create an array of visual elements/containers (s:Group, to be precise), and each Group will contain a set of Labels as elements.


      I've tried using both Array and ArrayCollection but am having a problem.


      It seems to work okay if I simply use groupsArray:Array and do something like:


      for (var i:int=0; i<totalGroups;i++) {

           (for var labelNum=0;labelNum<maxLabels;labelNum++) labelGroup.addElement(someLabel);

           groupsArray[i] = labelGroup;




      When I add groupsArray[1] as a Panel element, the labels show up... the problem is, they are all stacked right on top of each other.


      So what I need to do is be able to set Group.x, Group.y, Group.width, Group.layout, etc.


      But when I try to do this, nothing shows up in the group.  What's more baffling is that something WILL show up okay for the final group in the queue, but not any of the others... only the last index in the array; I'm trying to set the properties using:


      groupsArray[i].width = 300;



      I thought maybe I could fix it by using an ArrayCollection, creating each group (with properties), and then using groupsArray.addElement(myGroup) and groupsArray.getItemAt(index)... but none of this seems to work...


      The thing that confuses me the most is: (1) i'm getting no compile or runtime errors; and (2) the correct group and its label children show up fine (with x, y, width, and layout correct) for the very last item in the array, but none of the others...

        • 1. Re: Objects in Array / ArrayCollection with FlowLayout
          kid electric Level 1

          Okay, dug a little deeper and it looks like the issue may have to do with the fact that I am trying to use the FlowLayout extension as the layout (otherwise I would have just used something like HGroup instead of Group, but the problem is that this doesn't allow for constraint of the Labels to continue vertically when out of space horizontally in the group width)


          If I don't try to set layout it works, but if I set:


          var myLayout:FlowLayout = new FlowLayout();

          myGroup.layout = myLayout;


          it doesn't give me an error, but it also doesn't work when I assign


          groupsArray[i] = myGroup;


          or (for ArrayCollection)






          Any ideas why I can't assign this layout if it's contained in an Array? (I guess maybe I need to dig into the FlowLayout code and see what it's doing)  Assigning FlowLayout works fine when I am just adding the group right then and there to visual display/canvas area

          • 2. Re: Objects in Array / ArrayCollection with FlowLayout
            kid electric Level 1

            Would it be possible to create a Group extension, something like HGroup or VGroup but instead it would be FlowGroup which automatically uses the FlowLayout layout as its LayoutBase?

            • 3. Re: Objects in Array / ArrayCollection with FlowLayout
              Flex harUI Adobe Employee

              Can you post a 20-line test case?

              • 4. Re: Objects in Array / ArrayCollection with FlowLayout
                kid electric Level 1

                here's a basic example:


                var groupArray:ArrayCollection = new ArrayCollection();

                var groupLayout:HorizontalLayout = new HorizontalLayout();


                for (var i:int=0;i < 10;i++) {


                var pageGroup:Group = new Group();

                pageGroup.x = 60;

                pageGroup.y = 60;

                pageGroup.width = 300;

                pageGroup.layout = groupLayout;


                // parse through XML file for the page and for each word, insert it as a clickable text object

                for (var x:int=0;x < 20; x++) {

                     var wordLabel:Label = new Label();

                     wordLabel.text = "word"+x.toString();







                // tests:

                groupPanel.addElement(groupArray[1]); // shows nothing inside Panel

                groupPanel.addElement(groupArray[9]); // displays the Group (ie. all children labels) correctly inside Panel, with HorizontalLayout working


                // I have also tried: groupPanel.addElement(groupArray.getItemAt(1));

                // which gives compile error 1118: Implicit coercion of a value with static type Object to a possibly unrelated type mx.core:IVisualElement.



                <s:Panel id="groupPanel" />

                • 5. Re: Objects in Array / ArrayCollection with FlowLayout
                  Flex harUI Adobe Employee

                  It looks like you are trying to use a single HorizontalLayout instance for

                  multiple groups.  Each group needs its own layout instance.