Today I thought I would play around with the Fullscreen functionality of Actionscript. I found this great article over at Adobe which will further explain things.
To set this up, a few extra items were needed outside of the normal document class .as file.
- There needs to be a movie clip in the library bound to a class (I used myMC)
- The html source code that embeds the flash movie within your page needs to have the parameters allowFullScreen set to True and menu needs to be set to True as well. (Note, these are not default parameter values when you have Flash publish your html, so when testing you will need to verify these settings)
- Testing must be via your html file, so you will need to load the file in Firefox
Here is my document class FullScreen.as
package
{
import flash.display.MovieClip;
import flash.display.StageDisplayState;
import flash.events.ContextMenuEvent;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.ui.ContextMenuBuiltInItems;
/*
Reference: http://www.adobe.com/devnet/flashplayer/articles/full_screen_mode.html
*/
public class FullScreen extends MovieClip
{
private var FSText:String = "Right Click here to select screen sizing";
public function FullScreen()
{
// Editing the Context Menu
var fullscreenCM:ContextMenu = new ContextMenu();
fullscreenCM.addEventListener(ContextMenuEvent.MENU_SELECT, onContextMenuHandler);
fullscreenCM.hideBuiltInItems();
// add the full screen item
var fs:ContextMenuItem = new ContextMenuItem("Go Full Screen" );
fs.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onShowFullScreen);
fullscreenCM.customItems.push( fs );
// add the 'back to normal size' option
var xfs:ContextMenuItem = new ContextMenuItem("Exit Full Screen");
xfs.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onShowNormalScreen);
fullscreenCM.customItems.push( xfs );
// This is bound to a movieclip in your library with the class name of 'myMC'
var m:MovieClip = new myMC();
m.contextMenu = fullscreenCM;
addChild(m);
m.x = stage.stageWidth / 2;
m.y = stage.stageHeight / 2;
m.statusText.text = FSText;
}
public function onShowFullScreen(event:ContextMenuEvent):void
{
// Go Full Screen Option Selected
stage.displayState = StageDisplayState.FULL_SCREEN;
}
private function onShowNormalScreen(event:ContextMenuEvent):void
{
// Exit Full Screen Option Selected
stage.displayState = StageDisplayState.NORMAL;
}
private function onContextMenuHandler(event:ContextMenuEvent):void
{
// Enable and disable the context menu items based on what mode we are in.
if (stage.displayState == StageDisplayState.NORMAL)
{
event.target.customItems[0].enabled = true; // show full screen button
event.target.customItems[1].enabled = false; // hide normal screen button
}
else
{
event.target.customItems[0].enabled = false; // hide full screen button
event.target.customItems[1].enabled = true; // shoe normal screen button
}
}
}
}
great,
but can we have a contextmenu on the entire swf not just on a movieclip ?
Are we obliged to create a not empty movieclip to have a contextmenu ?
sorry for my school english (i’m french)
Hi benj,
I decided to update the code to allow the user to click anywhere on the stage. You simply don’t bind the contextMenu to the mc. Take a look here:
Demo Here
Thanks,
Morgan