This content has been marked as final. Show 6 replies
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.
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.
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.
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?
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.
Thanks, I realized that after I responded to your post. I appreciate your help!