6 Replies Latest reply on Jun 17, 2008 3:40 PM by stetzwebs

    Object width and height

    axiomflash Level 1
      I realize this isn't exactly the way that Flex works, but I need some help here:

      I have a UIComponent class that has graphics drawn inside of it (using graphics api and sprites). I need to be able to detect the width and height of this component. Since flex doesn't count these when i request clip.width or clip.height, I am totally stuck.

      The thing I really don't get is why in FlexBuilder3 I can see the dimensions I want right at the top of the variables list as $width and $height, but there is no way to get to them! Argh!

        • 1. Re: Object width and height
          peterent Level 2
          Your UIComponent doesn't have a width and a height unless you give one to it. That's usually done in the measure() method. You should override measure() and calculate a measuredWidth and a measuredHeight. The measure() method is called IF at least one of the dimensions to your component was not explicitly assigned.

          You must work with the Flex framework.
          • 2. Re: Object width and height
            I am having a similar problem, and this solution seems to not be working.

            I want to draw a box that's 10% height and 10% width of the canvas (with a height and a width that's defined by percentages as well) it's been drawn in. How do I do this? I can't seem to figure out how to access these. My goal is to fill in boxWidth and boxHeight in the code below.

            My code for creating the rectangle is attached. Thanks for any help.
            • 3. Re: Object width and height
              peterent2 Adobe Employee
              You have to let the Flex Framework do its job - you are trying to force it to draw things before it is ready to do so. In your file, override updateDisplayList and and draw into the graphics property of the newBox there.
              • 4. Re: Object width and height
                stetzwebs Level 1
                When you define a container to have a width and a height of 100%, then Flex has to, at some point, measure to find out exactly what those values are explicitly. I am wondering how I can access those so that I can assign a width and height to a box that is 10% of those values. Is there a way to access the canvas's height and width?
                • 5. Re: Object width and height
                  peterent2 Adobe Employee
                  When you override updateDisplayList in your component, the function is given the measured size of the component at point:

                  override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ) : void
                  // draw into your shape using unscaledWidth*.10 and unscaledHeight*.10

                  So just use 10% of those values.
                  • 6. Re: Object width and height
                    stetzwebs Level 1
                    Thanks, I realized that after I responded to your post. I appreciate your help!