| Package | flash.display |
| Class | public class Stage |
| Inheritance | Stage DisplayObjectContainer InteractiveObject DisplayObject EventDispatcher Object |
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
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.
accessibilityProperties
alpha
blendMode
cacheAsBitmap
contextMenu
filters
focusRect
loaderInfo
mask
mouseEnabled
name
opaqueBackground
rotation
scale9Grid
scaleX
scaleY
scrollRect
tabEnabled
tabIndex
transform
visible
x
y
See also
| Property | Defined By | ||
|---|---|---|---|
![]() | accessibilityProperties : AccessibilityProperties
The current accessibility options for this display object. | DisplayObject | |
| align : String
A value from the StageAlign class that specifies the alignment of the stage in
Flash Player or the browser. | Stage | ||
![]() | alpha : Number
Indicates the alpha transparency value of the object specified. | DisplayObject | |
![]() | blendMode : String
A value from the BlendMode class that specifies which blend mode to use. | DisplayObject | |
![]() | cacheAsBitmap : Boolean
If set to true, Flash Player caches an internal bitmap representation of the
display object. | DisplayObject | |
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance. | Object | |
![]() | contextMenu : ContextMenu
Specifies the context menu associated with this object. | InteractiveObject | |
| displayState : String
A value from the StageDisplayState class that specifies which display state to use. | Stage | ||
![]() | doubleClickEnabled : Boolean
Specifies whether the object receives doubleClick events. | InteractiveObject | |
| enableColorCorrection : Boolean
Enables Flash Player to display color correction that matches the main (primary)
monitor's International Color Consortium (ICC) color profile. | Stage | ||
![]() | filters : Array
An indexed array that contains each filter object currently associated with the display object. | DisplayObject | |
| 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. | Stage | ||
![]() | focusRect : Object
Specifies whether this object displays a focus rectangle. | InteractiveObject | |
| frameRate : Number
Gets and sets the frame rate of the stage. | Stage | ||
| fullScreenHeight : uint [read-only]
Returns the height of the monitor that will be used when going to full screen size, if that state
is entered immediately. | Stage | ||
| fullScreenSourceRect : Rectangle
Sets Flash Player to scale a specific region of the stage to full-screen mode. | Stage | ||
| fullScreenWidth : uint [read-only]
Returns the width of the monitor that will be used when going to full screen size, if that state
is entered immediately. | Stage | ||
| height : Number
Indicates the height of the display object, in pixels. | Stage | ||
![]() | loaderInfo : LoaderInfo [read-only]
Returns a LoaderInfo object containing information about loading the file
to which this display object belongs. | DisplayObject | |
![]() | mask : DisplayObject
The calling display object is masked by the specified mask object. | DisplayObject | |
| mouseChildren : Boolean
Determines whether or not the children of the object are mouse enabled. | Stage | ||
![]() | mouseEnabled : Boolean
Specifies whether this object receives mouse messages. | InteractiveObject | |
![]() | mouseX : Number [read-only]
Indicates the x coordinate of the mouse position, in pixels. | DisplayObject | |
![]() | mouseY : Number [read-only]
Indicates the y coordinate of the mouse position, in pixels. | DisplayObject | |
![]() | name : String
Indicates the instance name of the DisplayObject. | DisplayObject | |
| numChildren : int [read-only]
Returns the number of children of this object. | Stage | ||
![]() | opaqueBackground : Object
Specifies whether the display object is opaque with a certain background color. | DisplayObject | |
![]() | parent : DisplayObjectContainer [read-only]
Indicates the DisplayObjectContainer object that contains this display object. | DisplayObject | |
![]() | prototype : Object [static]
A reference to the prototype object of a class or function object. | Object | |
| quality : String
A value from the StageQuality class that specifies which rendering quality Flash Player uses. | Stage | ||
![]() | root : DisplayObject [read-only]
For a display object in a loaded SWF file, the root property is the
top-most display object in the portion of the display list's tree structure represented by that SWF file. | DisplayObject | |
![]() | rotation : Number
Indicates the rotation of the DisplayObject instance, in degrees, from its original orientation. | DisplayObject | |
![]() | scale9Grid : Rectangle
The current scaling grid that is in effect. | DisplayObject | |
| scaleMode : String
A value from the StageScaleMode class that specifies which scale mode to use. | Stage | ||
![]() | scaleX : Number
Indicates the horizontal scale (percentage) of the object as applied from the registration point. | DisplayObject | |
![]() | scaleY : Number
Indicates the vertical scale (percentage) of an object as applied from the registration point of the object. | DisplayObject | |
![]() | scrollRect : Rectangle
The scroll rectangle bounds of the display object. | DisplayObject | |
| showDefaultContextMenu : Boolean
Specifies whether to show or hide the default items in the Flash Player
context menu. | Stage | ||
![]() | stage : Stage [read-only]
The Stage of the display object. | DisplayObject | |
| stageFocusRect : Boolean
Specifies whether or not objects display a glowing border when they have focus. | Stage | ||
| stageHeight : int
The current height, in pixels, of the Stage. | Stage | ||
| stageWidth : int
Specifies the current width, in pixels, of the Stage. | Stage | ||
| tabChildren : Boolean
Determines whether the children of the object are tab enabled. | Stage | ||
![]() | tabEnabled : Boolean
Specifies whether this object is in the tab order. | InteractiveObject | |
![]() | tabIndex : int
Specifies the tab ordering of objects in a SWF file. | InteractiveObject | |
| textSnapshot : TextSnapshot [read-only]
Returns a TextSnapshot object for this DisplayObjectContainer instance. | Stage | ||
![]() | transform : Transform
An object with properties pertaining to a display object's matrix, color transform, and pixel bounds. | DisplayObject | |
![]() | visible : Boolean
Whether or not the display object is visible. | DisplayObject | |
| width : Number
Indicates the width of the display object, in pixels. | Stage | ||
![]() | x : Number
Indicates the x coordinate of the DisplayObject instance relative to the local coordinates of
the parent DisplayObjectContainer. | DisplayObject | |
![]() | y : Number
Indicates the y coordinate of the DisplayObject instance relative to the local coordinates of
the parent DisplayObjectContainer. | DisplayObject | |
| Method | Defined By | ||
|---|---|---|---|
Adds a child DisplayObject instance to this DisplayObjectContainer instance. | Stage | ||
Adds a child DisplayObject instance to this DisplayObjectContainer
instance. | Stage | ||
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event. | Stage | ||
![]() |
Indicates whether the security restrictions
would cause any display objects to be omitted from the list returned by calling
the DisplayObjectContainer.getObjectsUnderPoint() method
with the specified point point. | DisplayObjectContainer | |
![]() |
Determines whether the specified display object is a child of the DisplayObjectContainer instance or
the instance itself. | DisplayObjectContainer | |
Dispatches an event into the event flow. | Stage | ||
![]() |
Returns a rectangle that defines the area of the display object relative to the coordinate system
of the targetCoordinateSpace object. | DisplayObject | |
![]() |
Returns the child display object instance that exists at the specified index. | DisplayObjectContainer | |
![]() |
Returns the child display object that exists with the specified name. | DisplayObjectContainer | |
![]() |
Returns the index position of a child DisplayObject instance. | DisplayObjectContainer | |
![]() |
Returns an array of objects that lie under the specified point and are children
(or grandchildren, and so on) of this DisplayObjectContainer instance. | DisplayObjectContainer | |
![]() |
Returns a rectangle that defines the boundary of the display object,
based on the coordinate system defined by the targetCoordinateSpace
parameter, excluding any strokes on shapes. | DisplayObject | |
![]() |
Converts the point object from the Stage (global) coordinates
to the display object's (local) coordinates. | DisplayObject | |
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | Stage | ||
![]() |
Indicates whether an object has a specified property defined. | Object | |
![]() |
Evaluates the display object to see if it overlaps or intersects with the
obj display object. | DisplayObject | |
![]() |
Evaluates the display object to see if it overlaps or intersects with the
point specified by the x and y parameters. | DisplayObject | |
Calling the invalidate() method signals Flash Player 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). | Stage | ||
Determines whether the Stage.focus property returns null for
security reasons. | Stage | ||
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | |
![]() |
Converts the point object from the display object's (local) coordinates to the
Stage (global) coordinates. | DisplayObject | |
![]() |
Indicates whether the specified property exists and is enumerable. | Object | |
![]() |
Removes the specified child DisplayObject instance from the child list of the DisplayObjectContainer instance. | DisplayObjectContainer | |
Removes a child DisplayObject from the specified index position in the child list of
the DisplayObjectContainer. | Stage | ||
![]() |
Removes a listener from the EventDispatcher object. | EventDispatcher | |
Changes the position of an existing child in the display object container. | Stage | ||
![]() |
Sets the availability of a dynamic property for loop operations. | Object | |
![]() |
Swaps the z-order (front-to-back order) of the two specified child objects. | DisplayObjectContainer | |
Swaps the z-order (front-to-back order) of the child objects at the two specified index positions in the
child list. | Stage | ||
![]() |
Returns the string representation of the specified object. | Object | |
![]() |
Returns the primitive value of the specified object. | Object | |
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type. | Stage | ||
| Event | Summary | Defined By | ||
|---|---|---|---|---|
![]() | Dispatched when Flash Player gains operating system focus and becomes active. | EventDispatcher | ||
![]() | Dispatched when a display object is added to the display list. | DisplayObject | ||
![]() | Dispatched when a display object is added to the on stage display list, either directly or through the addition of a sub tree in which the display object is contained. | DisplayObject | ||
![]() | Dispatched when the user selects 'Clear' (or 'Delete') from the text context menu. | InteractiveObject | ||
![]() | Dispatched when a user presses and releases the main button of the user's pointing device over the same InteractiveObject. | InteractiveObject | ||
![]() | Dispatched when the user activates the platform specific accelerator key combination for a copy operation or selects 'Copy' from the text context menu. | InteractiveObject | ||
![]() | Dispatched when the user activates the platform specific accelerator key combination for a cut operation or selects 'Cut' from the text context menu. | InteractiveObject | ||
![]() | Dispatched when Flash Player loses operating system focus and is becoming inactive. | EventDispatcher | ||
![]() | Dispatched when a user presses and releases the main button of a pointing device twice in rapid succession over the same InteractiveObject when that object's doubleClickEnabled flag is set to true. | InteractiveObject | ||
![]() | Dispatched when the playhead is entering a new frame. | DisplayObject | ||
![]() | Dispatched when the playhead is exiting the current frame. | DisplayObject | ||
![]() | Dispatched after a display object gains focus. | InteractiveObject | ||
![]() | Dispatched after a display object loses focus. | InteractiveObject | ||
![]() | Dispatched after the constructors of frame display objects have run but before frame scripts have run. | DisplayObject | ||
| Dispatched by Flash Player when the Stage object enters, or leaves, full-screen mode. | Stage | |||
![]() | Dispatched when the user presses a key. | InteractiveObject | ||
![]() | Dispatched when the user attempts to change focus by using keyboard navigation. | InteractiveObject | ||
![]() | Dispatched when the user releases a key. | InteractiveObject | ||
![]() | Dispatched when a user presses the pointing device button over an InteractiveObject instance in the Flash Player window. | InteractiveObject | ||
![]() | Dispatched when the user attempts to change focus by using a pointer device. | InteractiveObject | ||
| Dispatched by the Stage object when the mouse pointer moves out of the Flash Player window area. | Stage | |||
![]() | Dispatched when a user moves the pointing device while it is over an InteractiveObject. | InteractiveObject | ||
![]() | Dispatched when the user moves a pointing device away from an InteractiveObject instance. | InteractiveObject | ||
![]() | Dispatched when the user moves a pointing device over an InteractiveObject instance in the Flash Player window. | InteractiveObject | ||
![]() | Dispatched when a user releases the pointing device button over an InteractiveObject instance in the Flash Player window. | InteractiveObject | ||
![]() | Dispatched when a mouse wheel is spun over an InteractiveObject instance in the Flash Player window. | InteractiveObject | ||
![]() | Dispatched when the user activates the platform specific accelerator key combination for a paste operation or selects 'Paste' from the text context menu. | InteractiveObject | ||
![]() | Dispatched when a display object is about to be removed from the display list. | DisplayObject | ||
![]() | Dispatched when a display object is about to be removed from the display list, either directly or through the removal of a sub tree in which the display object is contained. | DisplayObject | ||
![]() | Dispatched when the display list is about to be updated and rendered. | DisplayObject | ||
| Dispatched when the scaleMode property of the Stage object is set to StageScaleMode.NO_SCALE and the SWF file is resized. | Stage | |||
![]() | Dispatched when the user moves a pointing device away from an InteractiveObject instance. | InteractiveObject | ||
![]() | Dispatched when the user moves a pointing device over an InteractiveObject instance. | InteractiveObject | ||
![]() | Dispatched when the user activates the platform specific accelerator key combination for a select all operation or selects 'Select All' from the text context menu. | InteractiveObject | ||
![]() | Dispatched when the value of the object's tabChildren flag changes. | InteractiveObject | ||
![]() | Dispatched when the object's tabEnabled flag changes. | InteractiveObject | ||
![]() | Dispatched when the value of the object's tabIndex property changes. | InteractiveObject | ||
| align | property |
align:String [read-write] | Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
A value from the StageAlign class that specifies the alignment of the stage in Flash Player or the browser. The following are valid values:
| Value | Vertical Alignment | Horizontal |
|---|---|---|
StageAlign.TOP | Top | Center |
StageAlign.BOTTOM | Bottom | Center |
StageAlign.LEFT | Center | Left |
StageAlign.RIGHT | Center | Right |
StageAlign.TOP_LEFT | Top | Left |
StageAlign.TOP_RIGHT | Top | Right |
StageAlign.BOTTOM_LEFT | Bottom | Left |
StageAlign.BOTTOM_RIGHT | Bottom | Right |
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 Programming ActionScript 3.0.
public function get align():String public function set align(value:String):voidSee also
| displayState | property |
displayState:String [read-write] | Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9.0.28.0 |
A value from the StageDisplayState class that specifies which display state to use. The following are valid values:
StageDisplayState.FULL_SCREEN Sets Flash Player to expand the stage over the user's entire screen.StageDisplayState.NORMAL Sets the player 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 Flash Player transitions to full-screen mode, the Stage width and height
properties are updated, and Flash Player dispatches the Stage.resize event.
The following restrictions apply to SWF files that play within an HTML page (not those using the stand-alone Flash Player):
allowFullScreen parameter to the object
and embed tags in the HTML page that includes the SWF file, with allowFullScreen set
to "true", as shown in the following example:
<param name="allowFullScreen" value="true" />
...
<embed src="example.swf" allowFullScreen="true" ... >An HTML page may also use a script to generate SWF-embedding tags. You need to alter the script
so that it inserts the proper allowFullScreen settings. HTML pages generated by Flash and
Flex Builder use the AC_FL_RunContent() function to embed references to SWF files, and you
need to add the allowFullScreen parameter settings, as in the following:
AC_FL_RunContent( ... "allowFullScreen", "true", ... )
Stage.displayState without user input. While Flash Player is in full-screen mode, all keyboard input is disabled
(except keyboard shortcuts that take the user out of full-screen mode). A Flash Player 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.wmode in the HTML) to Opaque Windowless (opaque)
or Transparent Windowless (transparent), full-screen can be initiated, but the full-screen window will always be opaque. public function get displayState():String public function set displayState(value:String):voidSecurityError — Calling the displayState property of a Stage object throws an exception for
any caller that is not 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 caller by calling
the Security.allowDomain() method or the Security.allowInsecureDomain() method.
For more information, see the "Security" chapter in Programming ActionScript 3.0.
Trying to set the displayState property while the settings dialog is displayed, without a user response, or
if the param or embed HTML tag's allowFullScreen attribute is not set to
true throws a security error.
|
See also
displayState
property. Note: Fullscreen can only be triggered in certain situations, such as if the user has clicked or pressed a key, due to security restrictions. When run in a browser, the allowFullScreen property must be set to true.
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.*;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
public class FullScreenExample extends Sprite
{
private var videoURL:String = "testVideo.flv";
private var connection:NetConnection;
private var stream:NetStream;
private var video:Video;
public function FullScreenExample() {
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect(null);
loaderInfo.addEventListener(Event.INIT, createMouseListener);
}
private function createMouseListener(event:Event):void {
stage.addEventListener(MouseEvent.CLICK,toggleFullScreen);
}
private function toggleFullScreen(event:MouseEvent):void {
switch(stage.displayState) {
case "normal":
stage.displayState = "fullScreen";
break;
case "fullScreen":
default:
stage.displayState = "normal";
break;
}
}
// Video related:
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Unable to locate video: " + videoURL);
break;
}
}
private function connectStream():void {
var stream:NetStream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
video = new Video(stage.stageWidth,stage.stageHeight);
video.attachNetStream(stream);
stream.play(videoURL);
addChild(video);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function asyncErrorHandler(event:AsyncErrorEvent):void {
// ignore AsyncErrorEvent events.
}
}
}| enableColorCorrection | property |
enableColorCorrection:Boolean [read-write] | Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 10 |
Enables Flash Player to display color correction that matches the main (primary) monitor's International Color Consortium (ICC) color profile. Color correction works only if the main monitor is assigned a valid ICC color profile, which specifies the device's particular color attributes.
Use the flash.system.capabilities.hasColorCorrection property
to determine if color correction is available on the current system.
If color correction is available, all colors on the stage are assumed to be in
the sRGB color space, which is the most standard color space. Source profiles of input devices are not considered during color correction.
No input color correction is applied; only the stage output is mapped to the main
monitor's ICC color profile.
In general, the benefits to activating color management include predictable and consistent color, better conversion, accurate proofing and more efficient cross-media output. Be aware, though, that color management does not provide perfect conversions due to devices having a different gamut from each other or original images. Nor does color management eliminate the need for custom or edited profiles. Color profiles are dependent on browsers, operating systems (OS), OS extensions, output devices, and application support.
Applying color correction degrades Flash Player performance.
Flash Player's color correction is a document style color correction because
all SWF movies are considered documents with implicit sRGB profiles.
Use the enableColorCorrection property to tell Flash Player
to correct colors as best as it can when displaying the SWF (document) to the display color space.
Flash Player only compensates for differences between monitors, not for differences between input devices (camera/scanner/etc.).
flash10 function get enableColorCorrection():Boolean flash10 function set enableColorCorrection(value:Boolean):voidSee also
| focus | property |
focus:InteractiveObject [read-write] | Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
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.
public function get focus():InteractiveObject public function set focus(value:InteractiveObject):voidError — Throws an error if focus cannot be set to the target.
|
| frameRate | property |
frameRate:Number [read-write] | Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
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: Flash Player 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.
public function get frameRate():Number public function set frameRate(value:Number):voidSecurityError — Calling the frameRate property of a Stage object throws an exception for
any caller that is not 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 caller by calling
the Security.allowDomain() method or the Security.allowInsecureDomain() method.
For more information, see the "Security" chapter in Programming ActionScript 3.0.
|
| fullScreenHeight | property |
fullScreenHeight:uint [read-only] | Language Version : | ActionScript 3.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'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.
public function get fullScreenHeight():uintSee also
enterFullScreen() event handler,
which sets the fullScreenSourceRect property and enters full screen mode. To set the
fullScreenSourceRect property, the event handler starts with the location and dimensions of the
red square. It then compares the aspect ratio (width divided by height) of the red square to the
aspect ratio of the stage at full screen width and height so that it can expand the rectangle
(fullScreenSourceRect) to match the screen's aspect ratio. The result is that the red
square occupies the entire height of the monitor with the green background visible on each side.
If the aspect ratio was not matched, the stage background color, which is white by default, would show
on each side instead of the green background.
Note: Test this example in the browser. In the Flash Publish Settings dialog, on the HTML tab, select the template Flash Only - Allow Full Screen. Specify the Flash Player version 9.0.115.0, and make sure the Flash and HTML formats are selected on the Formats tab. Then publish and open the resulting HTML file in the browser.
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
// cover the stage with a green rectangle
var greenRect:Sprite = new Sprite();
greenRect.graphics.beginFill(0x00FF00);
greenRect.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
addChild(greenRect);
// create red square on stage, turn it into a button for going to full screen
var redSquare:Sprite = new Sprite();
redSquare.graphics.beginFill(0xFF0000);
redSquare.graphics.drawRect(0, 0, 300, 300);
redSquare.x = 50;
redSquare.y = 50;
redSquare.addEventListener(MouseEvent.CLICK, enterFullScreen);
redSquare.buttonMode = true;
addChild(redSquare);
function enterFullScreen(e:MouseEvent):void
{
// we will go to full screen zoomed in on the red square
var redSquare:Sprite = e.target as Sprite;
var fullScreenRect:Rectangle = new Rectangle(redSquare.x, redSquare.y, redSquare.width, redSquare.height);
// calculate aspect ratio of the red square
var rectAspectRatio:Number = fullScreenRect.width / fullScreenRect.height;
// calculate aspect ratio of the screen
var screenAspectRatio:Number = stage.fullScreenWidth / stage.fullScreenHeight;
// change the fullScreenRect so that it covers the entire screen, keeping it centered on the redSquare
// try commenting out this section to see what happens if you do not fix the aspect ratio.
if (rectAspectRatio > screenAspectRatio) {
var newHeight:Number = fullScreenRect.width / screenAspectRatio;
fullScreenRect.y -= ((newHeight - fullScreenRect.height) / 2);
fullScreenRect.height = newHeight;
} else if (rectAspectRatio < screenAspectRatio) {
var newWidth:Number = fullScreenRect.height * screenAspectRatio;
fullScreenRect.x -= ((newWidth - fullScreenRect.width) / 2);
fullScreenRect.width = newWidth;
}
// go to full screen
stage.fullScreenSourceRect = fullScreenRect;
stage.displayState = StageDisplayState.FULL_SCREEN;
}
| fullScreenSourceRect | property |
fullScreenSourceRect:Rectangle [read-write] | Language Version : | ActionScript 3.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 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, 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 the fullScreenSourceRect=null in ActionScript 3.0, and undefined in ActionScript 2.0.
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 www.adobe.com/go/display_settings.
public function get fullScreenSourceRect():Rectangle public function set fullScreenSourceRect(value:Rectangle):voidSee also
import flash.geom.*;
{
stage.fullScreenSourceRect = new Rectangle(0,0,320,240);
stage.displayState = StageDisplayState.FULL_SCREEN;
}Before using the full-screen mode with hardware scaling, the following conditions must be met:
allowFullScreen
attribute must be set to true for the object and embed tag.
(The scripts that generate SWF-embedding tags must also allow for full screen.) For sample of
files that can be used for Flex Builder, see the article,
Exploring full-screen
mode in Flash Player 9.An FLV file is loaded using NetConnection and NetStream objects. Since the FLV file
is in the same directory as the SWF file and will connect via HTTP, the NetConnection.connect()
method's parameter is set to null. The connect NetConnection object
reports its status by dispatching a netStatus event which invokes
the netStatusHandler() method. The netStatusHandler() method
checks if the connection was successful and invokes connectStream() method,
which creates a NetStream object that takes the NetConnection object as a parameter.
It also creates a video object and attached the NetStream object to the video object.
The video object then is added to the display list and the stream is set to play. Since
the FLV video file does not contain metadata or cue point information, an AsyncError
event will be dispatched. A listener must be set up to handle the event. Here the listener
is set up and it ignores the event. Another listener for netStatus event is also
set up for the NetStream object. It will display an error message if the stream was not found.
(Note that netStatusHandler() could be used to handle any number of different
status information reported for the stream or connection.)
When the properties and methods of a loaded SWF file are accessible, the
createMouseListener() method is invoked. It sets up an event listener for when
the mouse is clicked on the stage. The toggleFullScreen() method checks if
the display state is in the full or normal screen mode. If it is normal, the size of the video object
is set to the size of the video stream. The fullScreenSourceRect property is set
to a rectangle matching the dimensions of the video object. Then the Stage.displayMode
property is set to full screen, which causes the video in the source rectangle to expand to fill
the full screen area. If system requirements are met, the machine's graphics hardware will be
used to improve the performance of the full-screen video rendering and the display state is set
to full-screen mode. In order to catch any security error that may occur while switching to
the full-screen mode, a try...catch is used. (Note that the display state must be
set to full-screen mode after the fullScreenSourceRect property is set.) Before
switching to the normal-screen mode, the video object's width and height are set back to the saved
original video object's width and height. Otherwise, the changes made to the video object for
the full-screen mode will determine the width and height.
package {
import flash.display.Sprite;
import flash.display.StageDisplayState;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
import flash.events.AsyncErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.geom.Rectangle;
public class Stage_fullScreenSourceRectExample2 extends Sprite {
private var videoURL:String = "testVideo1.flv";
private var connection:NetConnection;
private var stream:NetStream;
private var myVideo:Video;
private var savedWidth:uint;
private var savedHeight:uint;
public function Stage_fullScreenSourceRectExample2() {
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect(null);
loaderInfo.addEventListener(Event.INIT, createMouseListener);
}
private function createMouseListener(event:Event):void {
stage.addEventListener(MouseEvent.CLICK, toggleFullScreen);
}
private function toggleFullScreen(event:MouseEvent):void {
if(stage.displayState == StageDisplayState.NORMAL) {
myVideo.width = myVideo.videoWidth;
myVideo.height = myVideo.videoHeight;
try {
stage.fullScreenSourceRect = new Rectangle(myVideo.x, myVideo.y,
myVideo.width, myVideo.height);
stage.displayState = StageDisplayState.FULL_SCREEN;
} catch (e:SecurityError) {
trace ("A security error occurred while switching to full screen: " + event);
myVideo.width = savedWidth;
myVideo.height = savedHeight;
}
}else {
myVideo.width = savedWidth;
myVideo.height = savedHeight;
stage.displayState = StageDisplayState.NORMAL;
}
}
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace ("Unable to locate video: " + videoURL);
break;
}
}
private function connectStream():void {
var stream:NetStream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
myVideo = new Video();
myVideo.attachNetStream(stream);
stream.play(videoURL);
savedWidth = myVideo.width;
savedHeight = myVideo.height;
addChild(myVideo);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function asyncErrorHandler(event:AsyncErrorEvent):void {
}
}
}
| fullScreenWidth | property |
fullScreenWidth:uint [read-only] | Language Version : | ActionScript 3.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'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.
public function get fullScreenWidth():uintSee also
enterFullScreen() event handler,
which sets the fullScreenSourceRect property and enters full screen mode. To set the
fullScreenSourceRect property, the event handler starts with the location and dimensions of the
red square. It then compares the aspect ratio (width divided by height) of the red square to the
aspect ratio of the stage at full screen width and height so that it can expand the rectangle
(fullScreenSourceRect) to match the screen's aspect ratio. The result is that the red
square occupies the entire height of the monitor with t