4 Replies Latest reply on Mar 29, 2010 2:31 PM by sakibi15

    HBox Styling - Dynamic Positioning

    sakibi15 Level 1

      Hey folks.

       

      Situation: I am creating a game for a fellow employer. I have HBoxes inside VBoxes, and this is all done through pure as3 code, no CData scripts in the MXML file or whatever. I'm going to be adding flash assets (of type Sprite) onto the HBoxes, I've already created a wrapper class that extends UIComponent and takes in a Sprite in the conctructor. I drew a complex rectangle shape in the HBox. I want to have dynamic positioning of the flash assets I load into the HBox, nothing like asset1.x = 50; asset2.x = 150. When its loaded, I want it to automatically float left and what not. Remember, this is all done through pure as3, everything from instantation to styling, no external stuff either.

       

      Goal: Children of my HBox need to have around 40 pixels of space between them organized in a horizontal manner (hence HBox).

       

      Attempted: I've tried myBox.setStyle("horizontalGap", 40) and although there is an increase in the horizontalGap property (I traced it out before and after, original value was 8 and is now 40), there is no visual difference, as in when I add multiple flash assets onto the HBox, they are not dispersed horizontally by 40 pixels...they're all on top of each other.

        • 1. Re: HBox Styling - Dynamic Positioning
          jsd99 Level 3

          Are you sure you're adding your objects as children of the HBox?  I do what you're doing all the time and it works - the HBox automatically reflows the contents.  It sounds like you're adding things to a canvas instead of an Hbox.

          • 2. Re: HBox Styling - Dynamic Positioning
            skider Level 1

            One possibility is that although your flash assets have the correct width, it is not being accurately transferred to the container component. I've run into problems like this before where the containing component had a width and height of 0, despite containing an object that had a non-zero width and height.

            • 3. Re: HBox Styling - Dynamic Positioning
              sakibi15 Level 1

              Hey,

               

                          hbox1.addChild(new SpriteUIComponent(a));
                          hbox1.addChild(new SpriteUIComponent(b));

               

                          hbox1.setStyle("horizontalGap", 40);

               

              Thats the code that I'm running, a and b are just some sprite objects I created thats created like var a:Sprite = Sprite(new randomShape()); where randomShape is a black octagon of some sort. So yeah, I am adding it to the HBox, not the canvas.

              • 4. Re: HBox Styling - Dynamic Positioning
                sakibi15 Level 1

                @ skyder

                 

                Unfortunately the issue isn't that the flash assets have a width and height of 0 (meaning it wouldn't be visible), its just that they don't have any seperation between each other, which they should cause I do something like hbox1.setStyle("horizontalGap", 40); meaning whatever I add to the hbox is organized in a horizontal manner of about 40 pixels in between each other. In this case, whatever I'm adding is not being dispersed...they're just added on top of each other.