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