2 Replies Latest reply on Feb 5, 2008 1:08 PM by peterent

    super newbie drawing help

      Hey all...im a super newbie and this is probably easy, I just can't find what i need in the documentation..so im hopping you guys can give me some insight. I'm trying to figure out how to draw vectors using AS on some container in flex. Flash makes it super easy, but I haven't had much luck with flex. Any help would be awesome...once I get better at this..i'll try and return the favor

        • 1. Re: super newbie drawing help
          johnnytapley Level 1
          ok so somone posted how to draw a line...that will cover 80% of what i need, how do an addChild() to a component...say a container of some sort. If I am able to move the container, will it redraw/resize the object?
          • 2. Re: super newbie drawing help
            peterent Level 2
            Let's say you want to make a Flex Canvas that draws a red X from corner to corner, no matter what size the Canvas is. Here's how you do that:

            1. Create a new ActionScript class, extending Canvas. You can also do this with an MXML file with Canvas as the root tag if you are more comfortable doing that.

            2. In your file, override the updateDisplayList function to draw the X:

            override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ) : void
            super.updateDisplayList( unscaledWidth, unscaledHeight );

            graphics.lineStyle( 2, 0xFF0000 ); // 2 pixel red lines
            graphics.moveTo( 0, 0 );
            graphics.lineTo( unscaledWidth, unscaledHeight );
            graphics.moveTo( unscaledWidth, 0 );
            graphics.lineTo( 0, unscaledHeight );
            } // end of updateDisplayList

            That's it. Whenever the Canvas change's size, the updateDisplayList function will be called. Using graphics.clear() will erase the previous X.

            You can get fancier and create a child UIComponent and then draw the X into that if you like, and if you choose to do that, use that's child's graphics property and create the child by overriding the createChildren() function.