In order to make this correctly you must consider the layout architecture of UIComponents, basicaly what you are asking is made by the layoutManager when it invalidates size of the component, thats the right moment to calculate width and height and set the measuredWidth and measuredHeight properties of the compoenet, that in the end leads to the width and height of it.
Getting the with and height right after you draw a line will probabbly get it wrong for the reasons I just said, a possible work arround is to draw the line not on the UIComponent itself but on a Shape component that's a Child of the UIComponent, this way you'll get the size and also be able to implement a correct Measure Method.
If this post answers your question or helps, please mark it as such.
If you are using auto-layout, the x and y and width and height might not be accessible (meaning they may appear to be 0), so keep that in mind.
Well i am calling the invalidate displaylist as well at the creationComplete. In this case too the width and height are both 0. It should give the right value as by this the layouy manager has been called.
Well it is 0 as layout manager has not been called. But if invalidateDisplayList is called at creationComplete i should get the right height and width this time.
nice, this is giving the answer, but i think this only tells us the start and the end point and not the height and the width coz this.height & this.width at the same location gives them to be 0.How come?
1 person found this helpful
There is a lifecycle of events and methods. See the doc on custom components. The final width/height of a UIComponent is not available right away.
Flex SDK Developer
Adobe Systems Inc.
I think I didn't explain it right the first time. Use a SHAPE object to draw your line, Shape will allow you to get the native functions of with and height so you will get them right, insert the shape into the UIComponent with addChild that will work.
By having a Shape object you'll also be able to implement correctly the measure method.
Thanks to all, for the help.