Working with the Stage : stage « Development « Flash / Flex / ActionScript






Working with the Stage

 

package{
  import flash.display.Sprite;
  import flash.display.Stage;
  import flash.display.StageAlign;
  import flash.display.StageScaleMode;
  import flash.display.DisplayObjectContainer;
  import flash.events.Event;

  public class Main extends Sprite
  {
         public function Main()
         {
                this.graphics.beginFill(0xff0000, 1);
                this.graphics.drawRect(0, 0, stage.stageWidth/2, stage.stageHeight/2);
                this.graphics.endFill();
                //set what part of the browser the stage will set itself in
                this.stage.align = StageAlign.TOP_LEFT;
                //set how the stage scales itself
                this.stage.scaleMode = StageScaleMode.NO_SCALE;
                //add an event listener for the stages resized event
                stage.addEventListener(Event.RESIZE, stageResized);

          }

         private function stageResized(event:Event):void
         {
                trace(stage.stageHeight+"  "+stage.stageWidth);

                this.graphics.clear();
                this.graphics.beginFill(0xff0000, 1);
                this.graphics.drawRect(0, 0, stage.stageWidth/2, stage.stageWidth/2);
                this.graphics.endFill();
        }
  }
}

        








Related examples in the same category

1.Setting the Frame Rate
2.Traversing Objects in a Display Hierarchy
3.Recursive display list tree traversal
4.Distinguishing Events Targeted at an Object from Events Targeted at That Object's Descendants
5.responds to mouse clicks that occur over any object on the display list, but not over a vacant area of the Stage instance
6.A stretchy layout
7.Simple Scribble
8.Local Global Sample