topical media & game development

talk show tell print

#graphic-flex-draw-classes-DrawingSolidFills.ax

#graphic-flex-draw-classes-DrawingSolidFills.ax [swf] [flash] flex


  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 @ax-graphic-flex-draw-classes-DrawingSolidFills extends Sprite {
  
                  
Constructor. Sets up listener for mouse click and draws initial background.

  
                  public function @ax-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();
                  }
  
          }
  
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.