package { import flash.display.Sprite; import flash.events.*; [SWF(width=550, height=400, backgroundColor=0xFFFFFF)] /** * Redraws the background of the stage every mouse click. */ public class graphic_flex_draw_classes_DrawingSolidFills extends Sprite { /** * Constructor. Sets up listener for mouse click and draws initial background. */ public function graphic_flex_draw_classes_DrawingSolidFills() { super(); this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); } private function onAddedToStage(e:Event):void { this.init(); } private function init():void { stage.addEventListener(MouseEvent.CLICK, onStageClick); drawBackground(); } /** * Draws a solid rectangle of random color over the stage. */ private function drawBackground():void { graphics.clear(); graphics.beginFill(Math.random()*0xFFFFFF); graphics.lineTo(stage.stageWidth, 0); graphics.lineTo(stage.stageWidth, stage.stageHeight); graphics.lineTo(0, stage.stageHeight); graphics.lineTo(0, 0); graphics.endFill(); } /** * Handler for when the stage is clicked. Forces redraw(). */ private function onStageClick(event:MouseEvent):void { drawBackground(); } } }