PackageTop Level
Classpublic class Stage
InheritanceStage Inheritance Object

Player version: Flash Player 5 — (became a native object in Flash Player 6, which improved performance significantly).

The Stage class is a top-level class whose methods, properties, and handlers you can access without using a constructor. Use the methods and properties of this class to access and manipulate information about the boundaries of a SWF file.

In Flex, use the Application class rather than the Stage class.



Public Properties
 Property
  align : String
[static]Indicates the current alignment of the SWF file in the player or browser.
  displayState : String
[static]Sets Flash Player to play the movie in full-screen mode or to take Flash Player out of full-screen mode.
  fullScreenHeight : Number
[static]Returns the height of the monitor that will be used when going to full screen size, if that state is entered immediately.
  fullScreenSourceRect : Rectangle
[static]Sets Flash Player to scale a specific region of the stage to full-screen mode.
  fullScreenWidth : Number
[static]Returns the width of the monitor that will be used when going to full screen size, if that state is entered immediately.
  height : Number
[static]Property (read-only); indicates the current height, in pixels, of the Stage.
  scaleMode : String
[static]Indicates the current scaling of the SWF file within Flash Player.
  showMenu : Boolean
[static]Specifies whether to show or hide the default items in the Flash Player context menu.
  width : Number
[static]Property (read-only); indicates the current width, in pixels, of the Stage.
  wmodeGPU : Boolean
[static]Indicates whether GPU compositing is available and in use.
 Properties inherited from class Object
 __proto__, __resolve, constructor, prototype
Public Methods
 Method
  
addListener(listener:Object):Void
[static]Detects when a SWF file is resized (but only if Stage.scaleMode = "noScale").
  
[static]Removes a listener object created with addListener().
 Methods inherited from class Object
 addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch
Events
 EventSummaryDefined by
  
onFullScreen = function(bFull:Boolean) {}
Invoked when the movie enters, or leaves, full-screen mode.Stage
  
onResize = function() {}
Invoked when Stage.scaleMode is set to noScale and the SWF file is resized.Stage
Property detail
alignproperty
public static var align:String

Player version: Flash Player 6

Indicates the current alignment of the SWF file in the player or browser.

The following table lists the values for the align property. Any value not listed here centers the SWF file in Flash player or browser area, which is the default setting.

Value Vertical Horizontal
"T" top center
"B" bottom center
"L" center left
"R" center right
"TL" top left
"TR" top right
"BL" bottom left
"BR" bottom right


Example
The following example demonstrates different alignments of the SWF file. Add a ComboBox instance to your document with the instance name stageAlign_cb. Add the following ActionScript to your FLA or AS file:
var stageAlign_cb:mx.controls.ComboBox;
stageAlign_cb.dataProvider = ['T', 'B', 'L', 'R', 'TL', 'TR', 'BL', 'BR'];
var cbListener:Object = new Object();
cbListener.change = function(evt:Object) {
    var align:String = evt.target.selectedItem;
    Stage.align = align;
};
stageAlign_cb.addEventListener("change", cbListener);
Stage.scaleMode = "noScale";

Select different alignment settings from the ComboBox.

displayStateproperty 
public static var displayState:String

Language version: ActionScript 2.0
Player version: Flash Player 9.0.28.0

Sets Flash Player to play the movie in full-screen mode or to take Flash Player out of full-screen mode. You can also use this property to check the current state of Flash Player.

The scaling behavior of the movie in full-screen mode is determined by the scaleMode setting (set using the Stage.scaleMode property or the SWF file's param or embed tag settings in the HTML file). If the scaleMode property is set to noScale while Flash Player makes the transition to full-screen mode, the stage width and height properties are updated and the Stage.onResize event listener is called.

The following restrictions apply to SWF files that play within an HTML page (not those using the standalone Flash Player):

See also


Example
The following example demonstrates how to display a SWF in full-screen mode. Note the above restrictions. Add a Button instance to your document with the instance name myButton. Add the following ActionScript to your FLA or AS file:
var myButton:mx.controls.Button;
myButton.label = "Toggle Fullscreen";
myButton.setSize(150,22);
var buttonListener:Object = new Object();
buttonListener.click = function(evt:Object) {
    Stage.displayState = Stage.displayState == "normal" ? "fullScreen" : "normal";
};
myButton.addEventListener("click", buttonListener);

fullScreenHeightproperty 
public static var fullScreenHeight:Number

Language version: ActionScript 2.0
Player version: Flash Player 9.0.115.0

Returns the height of the monitor that will be used when going to full screen size, if that state is entered immediately. If the user has multiple monitors, the monitor that is used is the monitor that most of the stage is on at the time.

Note: If the user has the opportunity to move the browser from one monitor to another between retrieving the value and going to full screen size, this value could be incorrect. If you retrieve the value in an event handler that sets Stage.displayState to Stage.displayState = "fullScreen", the value will be correct.

This is the pixel height of the monitor. It is the same as the stage height would be if Stage.align were set to Stage.align = "TL" and Stage.scaleMode set to Stage.scaleMode = "noScale".

See also

fullScreenSourceRectproperty 
public static var fullScreenSourceRect:Rectangle

Language version: ActionScript 2.0
Player version: Flash Player 9.0.115.0

Sets Flash Player to scale a specific region of the stage to full-screen mode. If available, Flash Player scales in hardware, which uses the graphics and video card on a user's computer, and generally displays content more quickly than software scaling.

When this property is set to a valid rectangle and the displayState property is set to full-screen mode, Flash Player scales the specified area. The actual Stage size in pixels within ActionScript does not change. Flash Player enforces a minimum limit for the size of the rectangle to accommodate the standard "Press Esc to exit full-screen mode" message. This limit is usually around 260 by 30 pixels but can vary depending on platform and Flash Player version.

This property can only be set when Flash Player is not in full-screen mode. To use this property correctly, set this property first, then set the displayState property to full-screen mode.

To enable scaling, set the fullScreenSourceRect property to a rectangle object.

Stage.fullScreenSourceRect = Rectangle; // valid, will enable hardware scaling

To disable scaling, set the fullScreenSourceRect property to undefined in AS2.

Stage.fullScreenSourceRect = undefined;

The end user also can select within Flash Player Display Settings to turn off hardware scaling, which is enabled by default. For more information, see www.adobe.com/go/display_settings.

See also


Example
The following code adds a custom context menu containing items to allow your Flash movie to enter and leave full-screen mode:
//Rectangle is needed when using hardware scaling.

import flash.geom.Rectangle;

// functions to enter and leave full-screen mode
function goFullScreen()
{
    Stage["displayState"] = "fullScreen";
}

// An alternate full screen function that uses hardware scaling to display the upper left corner of the stage in full screen.
function goScaledFullScreen(){
    var screenRectangle:Rectangle = new Rectangle();
    screenRectangle.x = 0;
    screenRectangle.y = 0;
    screenRectangle.width=Stage.width/2;
    screenRectangle.height=Stage.height/2; 
    Stage["fullScreenSourceRect"] = screenRectangle;
    Stage["displayState"] = "fullScreen";
}

function exitFullScreen()
{
    Stage["displayState"] = "normal";
}
    // function to enable, disable context menu items, based on which mode we are in.
    function menuHandler(obj, menuObj)
    {
    if (Stage["displayState"] == "normal")
    {
        // if we're in normal mode, enable the 'go full screen' item, disable the 'exit' item
        menuObj.customItems[0].enabled = true;
        menuObj.customItems[1].enabled = false;
    }
    else
    {
        // if we're in full screen mode, disable the 'go full screen' item, enable the 'exit' item
        menuObj.customItems[0].enabled = false;
        menuObj.customItems[1].enabled = true;
    }
    }

// create a new context menu
var fullscreenCM:ContextMenu = new ContextMenu(menuHandler);

// hide the regular built-in items
fullscreenCM.hideBuiltInItems();

// now, add the items to enter and leave full screen mode
var fs:ContextMenuItem = new ContextMenuItem("Go Full Screen", goFullScreen);
fullscreenCM.customItems.push( fs );

var xfs:ContextMenuItem = new ContextMenuItem("Exit Full Screen", exitFullScreen);
fullscreenCM.customItems.push( xfs );

// now, attach the context menu to any movieclip in your movie.
// here we attach it to _root, (even though using _root is generally a bad idea,)
// so it will appear if you right click anywhere on the movie.
_root.menu = fullscreenCM;

fullScreenWidthproperty 
public static var fullScreenWidth:Number

Language version: ActionScript 2.0
Player version: Flash Player 9.0.115.0

Returns the width of the monitor that will be used when going to full screen size, if that state is entered immediately. If the user has multiple monitors, the monitor that is used is the monitor that most of the stage is on at the time.

Note: If the user has the opportunity to move the browser from one monitor to another between retrieving the value and going to full screen size, this value could be incorrect. If you retrieve the value in an event handler that sets Stage.displayState to Stage.displayState = "fullScreen";, the value will be correct.

This is the pixel width of the monitor. It is the same as the stage width would be if Stage.align were set to Stage.align = "TL" and Stage.scaleMode set to Stage.scaleMode = "noScale".

See also

heightproperty 
public static var height:Number

Player version: Flash Player 6

Property (read-only); indicates the current height, in pixels, of the Stage. When the value of Stage.scaleMode is noScale, the height property represents the height of Flash Player. When the value of Stage.scaleMode is not noScale, height represents the height of the SWF file.

See also


Example
This example creates a new listener object called stageListener. It then uses myListener to call onResize and define a function that will be called when onResize is triggered. Finally, the code adds the myListener object to the callback list of the Stage object. Listener objects allow multiple objects to listen for resize notifications.
this.createTextField("stageSize_txt", this.getNextHighestDepth(), 10, 10, 100, 22);
var stageListener:Object = new Object();
stageListener.onResize = function() {
    stageSize_txt.text = "w:"+Stage.width+", h:"+Stage.height;
};
Stage.scaleMode = "noScale";
Stage.addListener(stageListener);

scaleModeproperty 
public static var scaleMode:String

Player version: Flash Player 6

Indicates the current scaling of the SWF file within Flash Player. The scaleMode property forces the SWF file into a specific scaling mode. By default, the SWF file uses the HTML parameters set in the Publish Settings dialog box.

The scaleMode property can use the values "exactFit", "showAll", "noBorder", and "noScale". Any other value sets the scaleMode property to the default "showAll".

Note: the default setting is showAll, except when in test movie mode, where the default setting is noScale


Example
The following example demonstrates various scale settings for the SWF file. Add a ComboBox instance to your document with the instance name scaleMode_cb. Add the following ActionScript to your FLA or AS file:
var scaleMode_cb:mx.controls.ComboBox;
scaleMode_cb.dataProvider = ["showAll", "exactFit", "noBorder", "noScale"];
var cbListener:Object = new Object();
cbListener.change = function(evt:Object) {
    var scaleMode_str:String = evt.target.selectedItem;
    Stage.scaleMode = scaleMode_str;
};
scaleMode_cb.addEventListener("change", cbListener);

For another example, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download and decompress the Samples zip file and go to the ActionScript2.0\StageSize folder to access the stagesize.fla file.

showMenuproperty 
public static var showMenu:Boolean

Player version: Flash Player 6

Specifies whether to show or hide the default items in the Flash Player context menu. If showMenu is set to true (the default), all context menu items appear. If showMenu is set to false, only Settings and About Adobe Flash Player items appear.

See also


Example
The following example creates a clickable text link that lets the user enable and disable the Flash Player context menu.
this.createTextField("showMenu_txt", this.getNextHighestDepth(), 10, 10, 100, 22);
showMenu_txt.html = true;
showMenu_txt.autoSize = true;
showMenu_txt.htmlText = "<a href=\"asfunction:toggleMenu\"><u>Stage.showMenu = "+Stage.showMenu+"</u></a>";
function toggleMenu() {
    Stage.showMenu = !Stage.showMenu;
    showMenu_txt.htmlText = "<a href=\"asfunction:toggleMenu\"><u>Stage.showMenu = "+Stage.showMenu+"</u></a>";
}

widthproperty 
public static var width:Number

Player version: Flash Player 6

Property (read-only); indicates the current width, in pixels, of the Stage. When the value of Stage.scaleMode is "noScale", the width property represents the width of Flash Player. This means that Stage.width will vary as you resize the player window. When the value of Stage.scaleMode is not "noScale", width represents the width of the SWF file as set at author-time in the Document Properties dialog box. This means that the value of width will stay constant as you resize the player window.

See also


Example
This example creates a new listener object called stageListener. It then uses stageListener to call onResize and define a function that will be called when onResize is triggered. Finally, the code adds the stageListener object to the callback list of the Stage object. Listener objects allow multiple objects to listen for resize notifications.
this.createTextField("stageSize_txt", this.getNextHighestDepth(), 10, 10, 100, 22);
var stageListener:Object = new Object();
stageListener.onResize = function() {
    stageSize_txt.text = "w:"+Stage.width+", h:"+Stage.height;
};
Stage.scaleMode = "noScale";
Stage.addListener(stageListener);

wmodeGPUproperty 
public static var wmodeGPU:Boolean

Language version: ActionScript 2.0
Player version: Flash Player 10.0.32

Indicates whether GPU compositing is available and in use. The wmodeGPU value is true only when all three of the following conditions exist:

Specifically, the wmodeGPU property indicates one of the following:

  1. GPU compositing has not been requested or is unavailable. In this case, the wmodeGPU property value is false.
  2. GPU compositing has been requested (if applicable and available), but the environment is operating in "fallback mode" (not optimal rendering) due to limitations of the content. In this case, the wmodeGPU property value is true.
  3. GPU compositing has been requested (if applicable and available), and the environment is operating in the best mode. In this case, the wmodeGPU property value is also true.

In other words, the wmodeGPU property identifies the capability and state of the rendering environment.

The wmodeGPU property is useful to determine, at runtime, whether or not GPU compositing is in use. The value of wmodeGPU indicates if your content is going to be scaled by hardware, or not, so you can present graphics at the correct size. You can also determine if you're rendering in a fast path or not, so that you can adjust your content complexity accordingly.

For Flash Player in a browser, GPU compositing can be requested by the value of gpu for the wmode HTML parameter in the page hosting the SWF file. For other configurations, GPU compositing can be requested in the header of a SWF file (set using SWF authoring tools).

However, the wmodeGPU property does not identify the current rendering performance. Even if GPU compositing is "in use" the rendering process might not be operating in the best mode. To adjust your content for optimal rendering, use a Flash runtime debugger version, and set the DisplayGPUBlendsetting in your mm.cfg file.

Note: This property is always false when referenced from ActionScript that runs before the runtime performs its first rendering pass. For example, if you examine wmodeGPU from a script in Frame 1 of Adobe Flash Professional, and your SWF file is the first SWF file loaded in a new instance of the runtime, then the wmodeGPU value is false. To get an accurate value, wait until at least one rendering pass has occurred.

Method detail
addListener()method
public static function addListener(listener:Object):Void

Player version: Flash Player 6

Detects when a SWF file is resized (but only if Stage.scaleMode = "noScale"). The addListener() method doesn't work with the default movie clip scaling setting (showAll) or other scaling settings (exactFit and noBorder).

To use addListener(), you must first create a listener object. Stage listener objects receive notification from Stage.onResize.

Parameters
listener:Object — An object that listens for a callback notification from the Stage.onResize event.

See also


Example
This example creates a new listener object called stageListener. It then uses stageListener to call onResize and define a function that will be called when onResize is triggered. Finally, the code adds the stageListener object to the callback list of the Stage object. Listener objects allow multiple objects to listen for resize notifications.
this.createTextField("stageSize_txt", this.getNextHighestDepth(), 10, 10, 100, 22);
var stageListener:Object = new Object();
stageListener.onResize = function() {
    stageSize_txt.text = "w:"+Stage.width+", h:"+Stage.height;
};
Stage.scaleMode = "noScale";
Stage.addListener(stageListener);

removeListener()method 
public static function removeListener(listener:Object):Boolean

Player version: Flash Player 6

Removes a listener object created with addListener().

Parameters
listener:Object — An object added to an object's callback list with addListener().

Returns
Boolean — A Boolean value.

See also


Example
The following example displays the Stage dimensions in a dynamically created text field. When you resize the Stage, the values in the text field update. Create a button with an instance name remove_btn. Add the following ActionScript to Frame 1 of the Timeline.
this.createTextField("stageSize_txt", this.getNextHighestDepth(), 10, 10, 100, 22);
stageSize_txt.autoSize = true;
stageSize_txt.border = true;
var stageListener:Object = new Object();
stageListener.onResize = function() {
    stageSize_txt.text = "w:"+Stage.width+", h:"+Stage.height;
};
Stage.addListener(stageListener);

remove_btn.onRelease = function() {
    stageSize_txt.text = "Removing Stage listener...";
    Stage.removeListener(stageListener);
}

Select Control > Test Movie to test this example. The values you see in the text field are updated when you resize the testing environment. When you click remove_btn, the listener is removed and the values are no longer updated in the text field.

Event detail
onFullScreenevent handler

public onFullScreen = function(bFull:Boolean) {}

Language version: ActionScript 2.0
Player version: 

Invoked when the movie enters, or leaves, full-screen mode. You can check the SWF file's full-screen status using this handler, or you can check the status using the Stage.displayState property. Full-screen mode can be exited using ActionScript, or by the user invoking a keyboard shortcut, or if the focus changes from the full-screen window.

Parameters
bFull:Boolean — A Boolean value indicating whether the movie has entered (true) or exited (false) full-screen mode.

See also

onResizeevent listener 

public onResize = function() {}

Player version: Flash Player 6

Invoked when Stage.scaleMode is set to noScale and the SWF file is resized. You can use this event handler to write a function that lays out the objects on the Stage when a SWF file is resized.


      myListener.onResize = function()[
         // your statements here
      }
      


Example
The following example displays a message in the Output panel when the Stage is resized:The following example writes the results of the trace() method to the log file when the Stage is resized:
Stage.scaleMode = "noScale"
var myListener:Object = new Object();
myListener.onResize = function () {
    trace("Stage size is now " + Stage.width + " by " + Stage.height);
}
Stage.addListener(myListener);
// later, call Stage.removeListener(myListener)

See also