class Stage
package openfl.display
extends DisplayObjectContainer › InteractiveObject › DisplayObject › EventDispatcher
implements IModule
Available on all platforms
The Stage class represents the main drawing area.
For SWF content running in the browser (in Flash® Player), the Stage represents the entire area where Flash content is shown. For content running in AIR on desktop operating systems, each NativeWindow object has a corresponding Stage object.
The Stage object is not globally accessible. You need to access it
through the stage property of a DisplayObject instance.
The Stage class has several ancestor classes - DisplayObjectContainer, InteractiveObject, DisplayObject, and EventDispatcher - from which it inherits properties and methods. Many of these properties and methods are either inapplicable to Stage objects, or require security checks when called on a Stage object. The properties and methods that require security checks are documented as part of the Stage class.
In addition, the following inherited properties are inapplicable to Stage objects. If you try to set them, an IllegalOperationError is thrown. These properties may always be read, but since they cannot be set, they will always contain default values.
accessibilityPropertiesalphablendModecacheAsBitmapcontextMenufiltersfocusRectloaderInfomaskmouseEnablednameopaqueBackgroundrotationscale9GridscaleXscaleYscrollRecttabEnabledtabIndextransformvisiblexy
Some events that you might expect to be a part of the Stage class, such
as enterFrame, exitFrame,
frameConstructed, and render, cannot be Stage
events because a reference to the Stage object cannot be guaranteed to
exist in every situation where these events are used. Because these events
cannot be dispatched by the Stage object, they are instead dispatched by
every DisplayObject instance, which means that you can add an event
listener to any DisplayObject instance to listen for these events. These
events, which are part of the DisplayObject class, are called broadcast
events to differentiate them from events that target a specific
DisplayObject instance. Two other broadcast events, activate
and deactivate, belong to DisplayObject's superclass,
EventDispatcher. The activate and deactivate
events behave similarly to the DisplayObject broadcast events, except that
these two events are dispatched not only by all DisplayObject instances,
but also by all EventDispatcher instances and instances of other
EventDispatcher subclasses. For more information on broadcast events, see
the DisplayObject class.
Events:
fullScreen | Dispatched when the Stage object enters, or leaves, full-screen mode. A change in full-screen mode can be initiated through Haxe code, or the user invoking a keyboard shortcut, or if the current focus leaves the full-screen window. |
|---|---|
mouseLeave | Dispatched by the Stage object when the pointer moves out of the stage area. If the mouse button is pressed, the event is not dispatched. |
orientationChange | Dispatched by the Stage object when the stage orientation changes. Orientation changes can occur when the
user rotates the device, opens a slide-out
keyboard, or when the
Note: If the
|
orientationChanging | Dispatched by the Stage object when the stage orientation begins changing. Important: orientationChanging events are not dispatched on Android devices. Note: If the
|
resize | Dispatched when the |
stageVideoAvailability | Dispatched by the Stage object when the state of the stageVideos property changes. |
Static variables
staticread onlysupportsOrientationChange:Bool
Whether the application supports changes in the stage orientation (and device rotation).
See also:
Constructor
Variables
align:StageAlign
A value from the StageAlign class that specifies the alignment of the stage in Flash Player or the browser. The following are valid values:
The align property is only available to an object that is
in the same security sandbox as the Stage owner (the main SWF file). To
avoid this, the Stage owner can grant permission to the domain of the
calling object by calling the Security.allowDomain() method
or the Security.alowInsecureDomain() method. For more
information, see the "Security" chapter in the OpenFL
Developer's Guide.
read onlyallowsFullScreenInteractive:Bool
Specifies whether this stage allows the use of the full screen with text input mode
autoOrients:Bool
Specifies whether the stage automatically changes orientation when the device orientation changes.
The initial value of this property is derived from the autoOrients
element of the application descriptor and defaults to false. When
changing the property to false, the behavior is not guaranteed. On
some devices, the stage remains in the current orientation. On others,
the stage orientation changes to a device-defined "standard"
orientation, after which, no further stage orientation changes occur.
OpenFL target support: May be set when targeting Adobe AIR only.
Always returns false on all other targets. Orientation may be
restricted at build-time only in a project.xml file using
<app orientation="landscape"/> or <app orientation="portrait"/>.
Adobe AIR profile support: This feature is supported on mobile
devices, but it is not supported on desktop operating systems or AIR for
TV devices. You can test for support at run time using the
Stage.supportsOrientationChange property. See
AIR Profile Support
for more information regarding API support across multiple profiles.
See also:
read onlycontentsScaleFactor:Float
Specifies the effective pixel scaling factor of the stage. This
value is 1 on standard screens and HiDPI (Retina display)
screens. When the stage is rendered on HiDPI screens the pixel
resolution is doubled; even if the stage scaling mode is set to
StageScaleMode.NO_SCALE. Stage.stageWidth and Stage.stageHeight
continue to be reported in classic pixel units.
read onlycontext3D:Context3D
BETA**
The current Context3D the default display renderer.
This property is supported only when using hardware rendering.
read onlydeviceOrientation:StageOrientation
The physical orientation of the device.
On devices with slide-out keyboards, the state of the keyboard has a
higher priority in determining the device orientation than the rotation
detected by the accelerometer. Thus on a portrait-aspect device with a
side-mounted keyboard, the deviceOrientation property will report
ROTATED_LEFT when the keyboard is open no matter how the user is
holding the device.
Use the constants defined in the StageOrientation class when setting or comparing values for this property.
OpenFL target support: This feature is supported on iOS and Android
mobile devices, but it is not supported on desktop operating systems.
You can test for support at run time using the
Stage.supportsOrientationChange property.
AIR profile support: This feature is supported on mobile devices, but
it is not supported on desktop operating systems or AIR for TV devices.
You can test for support at run time using the
Stage.supportsOrientationChange property. See
AIR Profile Support
for more information regarding API support across multiple profiles.
displayState:StageDisplayState
A value from the StageDisplayState class that specifies which display state to use. The following are valid values:
StageDisplayState.FULL_SCREENSets the OpenFL application to expand the stage over the user's entire screen, with keyboard input disabled.StageDisplayState.FULL_SCREEN_INTERACTIVESets the OpenFL application to expand the stage over the user's entire screen, with keyboard input allowed. (Not available for content running in Adobe Flash Player.)StageDisplayState.NORMALSets the OpenFL application back to the standard stage display mode.
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 embed
tag settings in the HTML file). If the scaleMode property is
set to noScale while the application transitions to
full-screen mode, the Stage width and height
properties are updated, and the Stage dispatches a resize
event. If any other scale mode is set, the stage and its contents are
scaled to fill the new screen dimensions. The Stage object retains its
original width and height values and does not
dispatch a resize event.
The following restrictions apply to SWF files that play within an HTML page (not those using the stand-alone Flash Player or not running in the AIR runtime):
- To enable full-screen mode, add the
allowFullScreenparameter to theobjectandembedtags in the HTML page that includes the SWF file, withallowFullScreenset to"true", as shown in the following example: - Full-screen mode is initiated in response to a mouse click or key
press by the user; the movie cannot change
Stage.displayStatewithout user input. Flash runtimes restrict keyboard input in full-screen mode. Acceptable keys include keyboard shortcuts that terminate full-screen mode and non-printing keys such as arrows, space, Shift, and Tab keys. Keyboard shortcuts that terminate full-screen mode are: Escape (Windows, Linux, and Mac), Control+W(Windows), Command+W(Mac), and Alt+F4.
A Flash runtime dialog box appears over the movie when users enter full-screen mode to inform the users they are in full-screen mode and that they can press the Escape key to end full-screen mode.
- Starting with Flash Player 9.0.115.0, full-screen works the same in
windowless mode as it does in window mode. If you set the Window Mode
(
wmodein the HTML) to Opaque Windowless (opaque) or Transparent Windowless (transparent), full-screen can be initiated, but the full-screen window will always be opaque.
These restrictions are not present for SWF content running in the stand-alone Flash Player or in AIR. AIR supports an interactive full-screen mode which allows keyboard input.
For AIR content running in full-screen mode, the system screen saver and power saving options are disabled while video content is playing and until either the video stops or full-screen mode is exited.
On Linux, setting displayState to
StageDisplayState.FULL_SCREEN or
StageDisplayState.FULL_SCREEN_INTERACTIVE is an asynchronous
operation.
Throws:
SecurityError | Calling the |
|---|
focus:InteractiveObject
The interactive object with keyboard focus; or null if focus
is not set or if the focused object belongs to a security sandbox to which
the calling object does not have access.
Throws:
Error | Throws an error if focus cannot be set to the target. |
|---|
frameRate:Float
Gets and sets the frame rate of the stage. The frame rate is defined as frames per second. By default the rate is set to the frame rate of the first SWF file loaded. Valid range for the frame rate is from 0.01 to 1000 frames per second.
Note: An application might not be able to follow high frame rate settings, either because the target platform is not fast enough or the player is synchronized to the vertical blank timing of the display device (usually 60 Hz on LCD devices). In some cases, a target platform might also choose to lower the maximum frame rate if it anticipates high CPU usage.
For content running in Adobe AIR, setting the frameRate
property of one Stage object changes the frame rate for all Stage objects
(used by different NativeWindow objects).
Throws:
SecurityError | Calling the |
|---|
read onlyfullScreenHeight:UInt
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's 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, the value could be incorrect. If you retrieve the value
in an event handler that sets Stage.displayState to
StageDisplayState.FULL_SCREEN, the value will be correct.
This is the pixel height of the monitor and is the same as the stage
height would be if Stage.align is set to StageAlign.TOP_LEFT and
Stage.scaleMode is set to StageScaleMode.NO_SCALE.
fullScreenSourceRect:Rectangle
Sets OpenFL to scale a specific region of the stage to
full-screen mode. If available, the OpenFL 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, OpenFL scales the
specified area. The actual Stage size in pixels within Haxe
does not change. OpenFL 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 on platform and OpenFL version.
This property can only be set when the OpenFL is not in
full-screen mode. To use this property correctly, set this property
first, then set the displayState property to full-screen mode, as
shown in the code examples.
To enable scaling, set the fullScreenSourceRect property to a
rectangle object:
// valid, will enable hardware scaling
stage.fullScreenSourceRect = new Rectangle(0,0,320,240);
To disable scaling, set fullScreenSourceRect=null.
stage.fullScreenSourceRect = null;
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 <a href="http://www.adobe.com/go/display_settings" scope="external">www.adobe.com/go/display_settings.
read onlyfullScreenWidth:UInt
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's 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, the value could be incorrect. If you retrieve the value
in an event handler that sets Stage.displayState to
StageDisplayState.FULL_SCREEN, the value will be correct.
This is the pixel width of the monitor and is the same as the stage
width would be if Stage.align is set to StageAlign.TOP_LEFT and
Stage.scaleMode is set to StageScaleMode.NO_SCALE.
read onlynativeWindow:NativeWindow
Available on AIR, Android, HashLink, Linux, Neko, Windows, iOS, macOS
read onlyorientation:StageOrientation
The current orientation of the stage. This property is set to one of four values, defined as constants in the StageOrientation class:
| StageOrientation constant | Stage orientation |
|---|---|
StageOrientation.DEFAULT | The screen is in the default orientation (right-side up). |
StageOrientation.ROTATED_RIGHT | The screen is rotated right. |
StageOrientation.ROTATED_LEFT | The screen is rotated left. |
StageOrientation.UPSIDE_DOWN | The screen is rotated upside down. |
StageOrientation.UNKNOWN | The application has not yet determined the initial orientation of the screen. You can add an event listener for the orientationChange event |
To set the stage orientation, use the setOrientation() method.
quality:StageQuality
A value from the StageQuality class that specifies which rendering quality is used. The following are valid values:
StageQuality.LOW- Low rendering quality. Graphics are not anti-aliased, and bitmaps are not smoothed, but runtimes still use mip-mapping.StageQuality.MEDIUM- Medium rendering quality. Graphics are anti-aliased using a 2 x 2 pixel grid, bitmap smoothing is dependent on theBitmap.smoothingsetting. Runtimes use mip-mapping. This setting is suitable for movies that do not contain text.StageQuality.HIGH- High rendering quality. Graphics are anti-aliased using a 4 x 4 pixel grid, and bitmap smoothing is dependent on theBitmap.smoothingsetting. Runtimes use mip-mapping. This is the default rendering quality setting that Flash Player uses.StageQuality.BEST- Very high rendering quality. Graphics are anti-aliased using a 4 x 4 pixel grid. IfBitmap.smoothingistruethe runtime uses a high quality downscale algorithm that produces fewer artifacts (however, usingStageQuality.BESTwithBitmap.smoothingset totrueslows performance significantly and is not a recommended setting).
Higher quality settings produce better rendering of scaled bitmaps. However, higher quality settings are computationally more expensive. In particular, when rendering scaled video, using higher quality settings can reduce the frame rate.
In the desktop profile of Adobe AIR, quality can be set to
StageQuality.BEST or StageQuality.HIGH(and the
default value is StageQuality.HIGH). Attempting to set it to
another value has no effect (and the property remains unchanged). In the
moble profile of AIR, all four quality settings are available. The default
value on mobile devices is StageQuality.MEDIUM.
For content running in Adobe AIR, setting the quality
property of one Stage object changes the rendering quality for all Stage
objects (used by different NativeWindow objects).
Note: The operating system draws the device fonts, which are
therefore unaffected by the quality property.
Throws:
SecurityError | Calling the
can grant permission to the domain of the caller by
calling the |
|---|
scaleMode:StageScaleMode
A value from the StageScaleMode class that specifies which scale mode to use. The following are valid values:
StageScaleMode.EXACT_FIT- The entire application is visible in the specified area without trying to preserve the original aspect ratio. Distortion can occur, and the application may appear stretched or compressed.StageScaleMode.SHOW_ALL- The entire application is visible in the specified area without distortion while maintaining the original aspect ratio of the application. Borders can appear on two sides of the application.StageScaleMode.NO_BORDER- The entire application fills the specified area, without distortion but possibly with some cropping, while maintaining the original aspect ratio of the application.StageScaleMode.NO_SCALE- The entire application is fixed, so that it remains unchanged even as the size of the player window changes. Cropping might occur if the player window is smaller than the content.
Throws:
SecurityError | Calling the |
|---|
showDefaultContextMenu:Bool
Specifies whether to show or hide the default items in the Flash
runtime context menu.
If the showDefaultContextMenu property is set to true (the
default), all context menu items appear. If the
showDefaultContextMenu property is set to false, only the Settings
and About... menu items appear.
Throws:
SecurityError | Calling the |
|---|
softKeyboardRect:Rectangle
The area of the stage that is currently covered by the software keyboard. The area has a size of zero (0,0,0,0) when the soft keyboard is not visible.
When the keyboard opens, the softKeyboardRect is set at the time the
softKeyboardActivate event is dispatched. If the keyboard changes size
while open, the runtime updates the softKeyboardRect property and
dispatches an additional softKeyboardActivate event.
Note: On Android, the area covered by the keyboard is estimated
when the operating system does not provide the information necessary
to determine the exact area. This problem occurs in fullscreen mode
and also when the keyboard opens in response to an InteractiveObject
receiving focus or invoking the requestSoftKeyboard() method.
read onlystage3Ds:Vector<Stage3D>
A list of Stage3D objects available for displaying 3-dimensional content.
You can use only a limited number of Stage3D objects at a time. The number of available Stage3D objects depends on the platform and on the available hardware.
A Stage3D object draws in front of a StageVideo object and behind the OpenFL display list.
stageFocusRect:Bool
Specifies whether or not objects display a glowing border when they have focus.
Throws:
SecurityError | Calling the |
|---|
read onlystageHeight:Int
The current height, in pixels, of the Stage.
If the value of the Stage.scaleMode property is set to
StageScaleMode.NO_SCALE when the user resizes the window, the
Stage content maintains its size while the stageHeight
property changes to reflect the new height size of the screen area
occupied by the SWF file.(In the other scale modes, the
stageHeight property always reflects the original height of
the SWF file.) You can add an event listener for the resize
event and then use the stageHeight property of the Stage
class to determine the actual pixel dimension of the resized Flash runtime
window. The event listener allows you to control how the screen content
adjusts when the user resizes the window.
Air for TV devices have slightly different behavior than desktop
devices when you set the stageHeight property. If the
Stage.scaleMode property is set to
StageScaleMode.NO_SCALE and you set the
stageHeight property, the stage height does not change until
the next frame of the SWF.
Note: In an HTML page hosting the SWF file, both the
object and embed tags' height
attributes must be set to a percentage (such as 100%), not
pixels. If the settings are generated by JavaScript code, the
height parameter of the AC_FL_RunContent()
method must be set to a percentage, too. This percentage is applied to the
stageHeight value.
Throws:
SecurityError | Calling the |
|---|
read onlystageWidth:Int
Specifies the current width, in pixels, of the Stage.
If the value of the Stage.scaleMode property is set to
StageScaleMode.NO_SCALE when the user resizes the window, the
Stage content maintains its defined size while the stageWidth
property changes to reflect the new width size of the screen area occupied
by the SWF file.(In the other scale modes, the stageWidth
property always reflects the original width of the SWF file.) You can add
an event listener for the resize event and then use the
stageWidth property of the Stage class to determine the
actual pixel dimension of the resized Flash runtime window. The event
listener allows you to control how the screen content adjusts when the
user resizes the window.
Air for TV devices have slightly different behavior than desktop
devices when you set the stageWidth property. If the
Stage.scaleMode property is set to
StageScaleMode.NO_SCALE and you set the
stageWidth property, the stage width does not change until
the next frame of the SWF.
Note: In an HTML page hosting the SWF file, both the
object and embed tags' width
attributes must be set to a percentage (such as 100%), not
pixels. If the settings are generated by JavaScript code, the
width parameter of the AC_FL_RunContent()
method must be set to a percentage, too. This percentage is applied to the
stageWidth value.
Throws:
SecurityError | Calling the |
|---|
read onlysupportedOrientations:Vector<StageOrientation>
The orientations supported by the current device.
You can use the orientation strings included in this list as parameters
for the setOrientation() method. Setting an unsupported orientation
fails without error.
The possible orientations include:
| StageOrientation constant | Stage orientation |
|---|---|
StageOrientation.DEFAULT | The screen is in the default orientation (right-side up). |
StageOrientation.ROTATED_RIGHT | The screen is rotated right. |
StageOrientation.ROTATED_LEFT | The screen is rotated left. |
StageOrientation.UPSIDE_DOWN | The screen is rotated upside down. |
OpenFL target support: Returns orientation values when targeting Adobe AIR only. On all other targets, returns an empty vector.
Adobe AIR profile support: This feature is supported on mobile
devices, but it is not supported on desktop operating systems or AIR for
TV devices. You can test for support at run time using the
Stage.supportsOrientationChange property. See
AIR Profile Support
for more information regarding API support across multiple profiles.
See also:
Methods
invalidate():Void
Calling the invalidate() method signals Flash runtimes to
alert display objects on the next opportunity it has to render the display
list (for example, when the playhead advances to a new frame). After you
call the invalidate() method, when the display list is next
rendered, the Flash runtime sends a render event to each
display object that has registered to listen for the render
event. You must call the invalidate() method each time you
want the Flash runtime to send render events.
The render event gives you an opportunity to make changes
to the display list immediately before it is actually rendered. This lets
you defer updates to the display list until the latest opportunity. This
can increase performance by eliminating unnecessary screen updates.
The render event is dispatched only to display objects
that are in the same security domain as the code that calls the
stage.invalidate() method, or to display objects from a
security domain that has been granted permission via the
Security.allowDomain() method.
setOrientation(newOrientation:StageOrientation):Void
Sets the stage to the specified orientation.
Set the newOrientation parameter to one of the following four values
defined as constants in the StageOrientation class:
| StageOrientation constant | Stage orientation |
|---|---|
StageOrientation.DEFAULT | The screen is in the default orientation (right-side up). |
StageOrientation.ROTATED_RIGHT | The screen is rotated right. |
StageOrientation.ROTATED_LEFT | The screen is rotated left. |
StageOrientation.UPSIDE_DOWN | The screen is rotated upside down. |
Do not set the parameter to StageOrientation.UNKNOWN or any string
value other than those listed in the table.
Check the list provided by the supportedOrientations property to
determine which orientations are supported by the current device.
Setting the orientation is an asynchronous operation. It is not
guaranteed to be complete immediately after you call the
setOrientation() method. Add an event listener for the
orientationChange event to determine when the orientation change is
complete.
Note: The setOrientation() method does not cause an
orientationChanging event to be dispatched.
OpenFL target support: May be called when targeting Adobe AIR only.
Calls to this method are always ignored on all other targets. Orientation
may be restricted at build-time only in a project.xml file using
<app orientation="landscape"/> or <app orientation="portrait"/>.
Adobe AIR profile support: This feature is supported on mobile
devices, but it is not supported on desktop operating systems or AIR for
TV devices. You can test for support at run time using the
Stage.supportsOrientationChange property. See
AIR Profile Support
for more information regarding API support across multiple profiles.
See also:























