Accessibility

Table of Contents

Exploring full-screen mode in Flash Player 9

Sample application

As an example of how to use the new full-screen mode ActionScript, we show how to add a custom context menu containing items to allow your Flash movie to enter and leave full-screen mode. Take a Flash movie, any Flash movie, and add the following ActionScript to frame 1:

ActionScript 2.0 example

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

ActionScript 3.0 example

import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.display.*;
import flash.events.*;
import flash.geom.Rectangle;

// functions to enter and leave full screen mode
function goFullScreen(event:ContextMenuEvent):void
{
   stage.displayState = StageDisplayState.FULL_SCREEN;
}

// 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(0, 0, stage.stageWidth/2, stage.stageHeight/2);
   stage.fullScreenSourceRect = screenRectangle;
   stage.displayState = StageDisplayState.FULL_SCREEN;
}

function exitFullScreen(event:ContextMenuEvent):void
{
   stage.displayState = StageDisplayState.NORMAL;
}

// function to enable and disable the context menu items,
// based on what mode we are in.
function menuHandler(event:ContextMenuEvent):void
{
   if (stage.displayState == StageDisplayState.NORMAL)
   {
      event.target.customItems[0].enabled = true;
      event.target.customItems[1].enabled = false;
   }
   else
   {
      event.target.customItems[0].enabled = false;
      event.target.customItems[1].enabled = true;
   }
}

// create the context menu, remove the built-in items,
// and add our custom items
var fullscreenCM:ContextMenu = new ContextMenu();
fullscreenCM.addEventListener(ContextMenuEvent.MENU_SELECT, menuHandler);
fullscreenCM.hideBuiltInItems();

var fs:ContextMenuItem = new ContextMenuItem("Go Full Screen" );
fs.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, goFullScreen);
fullscreenCM.customItems.push( fs );

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

// finally, attach the context menu to a movieclip
mc.contextMenu = fullscreenCM;