9 Replies Latest reply on Jul 31, 2009 10:23 PM by Nishant28

    Drawing in Flex


      I am working on a code that has entities which can be connected by lines. The line extends UIComponent. Now to my understanding everything in flex is having an x, y, width and height which means they are all having a shape of a rectangle. When i connect two nodes a line is made(using the moveTo and lineTo graphics commands). Once such a link is made i am checking the height and width, they come to be 0.


      Then how come a component with height and width 0 can accomodate a graphics drawing?


      And how does this line component has the shape of the drawn line and not of a rectangle?


      Thanks in advance ...


      Message was edited by: Nishant28

        • 1. Re: Drawing in Flex
          Vikram_S Level 2



          try  getBounds().




          • 2. Re: Drawing in Flex



            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.

            • 3. Re: Drawing in Flex
              Gregory Lafrance Level 6

              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.

              • 4. Re: Drawing in Flex
                Nishant28 Level 1

                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.

                • 5. Re: Drawing in Flex
                  Nishant28 Level 1

                  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.

                  • 6. Re: Drawing in Flex
                    Nishant28 Level 1

                    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?

                    • 7. Re: Drawing in Flex
                      Flex harUI Adobe Employee

                      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.


                      Alex Harui

                      Flex SDK Developer

                      Adobe Systems Inc.

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

                      1 person found this helpful
                      • 8. Re: Drawing in Flex
                        buabco Level 1



                        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.

                        • 9. Re: Drawing in Flex
                          Nishant28 Level 1

                          Thanks to all, for the help.