Top Level

Class Stage

Object


public class Stage
extends 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.




Property Summary
static align : String
Indicates the current alignment of the SWF file in the player or browser.
static height : Number
Property (read-only); indicates the current height, in pixels, of the Stage.
static scaleMode : String
Indicates the current scaling of the SWF file within Flash Player.
static showMenu : Boolean
Specifies whether to show or hide the default items in the Flash Player context menu.
static width : Number
Property (read-only); indicates the current width, in pixels, of the Stage.

Properties inherited from class Object
__proto__, __resolve, constructor, prototype


Event Summary
onResize = function() {}
Invoked when Stage.scaleMode is set to noScale and the SWF file is resized.


Method Summary
static addListener(listener:Object) : Void
Detects when a SWF file is resized (but only if Stage.scaleMode = "noScale").
static removeListener(listener:Object) : Boolean
Removes a listener object created with addListener().

Methods inherited from class Object
addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch


Property Detail

align Property

public static 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.


height Property

public static 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.

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);

See also
Stage.align, Stage.scaleMode, Stage.width

scaleMode Property

public static 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);

To view another example, see the stagesize.fla file in the ActionScript samples Folder. The following list provides typical paths to the ActionScript samples Folder:


showMenu Property

public static 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 Macromedia Flash Player items appear.

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>";
}

See also
ContextMenu class, ContextMenuItem class

width Property

public static 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.

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);

See also
Stage.align, Stage.height, Stage.scaleMode


Event Detail

onResize Event 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
Stage.scaleMode, Stage.addListener(), Stage.removeListener()


Method Detail

addListener Method

public static 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.

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);

See also
Stage.onResize, Stage.removeListener()

removeListener Method

public static 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.

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.

See also
Stage.addListener()