This content has been marked as final. Show 2 replies
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?
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.