2 Replies Latest reply on Jun 11, 2009 7:56 AM by cory891

    Odd sizing behavior

    cory891

      I have a Sprite in the display list which contains another Sprite.  At one point in my program, I create a bitmap and add it to the child sprite.  Before the bitmap is added, the parent sprite has a width of 663, and the child is located at x-coordinate 0 and has a width of 0.  The bitmap's width is 527.  After I add the bitmap to the child sprite, the child sprite's width change to 527.  However, the parent sprite's width changes to 349401.  I have no idea where that gigantic value comes from.  The height property has the same issue.  My bitmap doesn't display correctly until I resize the browser window, and I assume that this has something to do with it.  After I resize, the width goes back to normal.

       

      Anybody know why adding a bitmap to a sprite could cause the width and height of the sprite's parent to change like this?

        • 1. Re: Odd sizing behavior
          Flex harUI Adobe Employee

          You might see funny numbers if things aren't on the display list yet.  Note that Flex keeps the entire app off the displaylist until applicationComplete

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Odd sizing behavior
            cory891 Level 1

            I figured out what is happening.  The base size of the sprite container is controlled strictly by the size and position of its children.  When you set the width and height parameters of the container, it increases or decreases in size by changing its scale factor.  So if you give it a width that is 50% bigger than the base width, all of the children will be scaled to be 50% bigger.  I need to absolutely position my objects like a Canvas component lets you do, but Canvas will only accept objects inheriting from UIComponent.

             

            So, I wrote my own class that inherits from Sprite.  I gave it a method setSize which takes a width and height.  setSize takes a Shape object and draws a rectangle from (0, 0) to (width, height).  This sets the size of the container to width x height, so that I can then absolutely position other children within this space. I had to override all of the functions that deal with indices and counts of children so that I could add or subtract 1 as appropriate so that the external code does not need to know about the child shape that has been added.  Now everything is working well.