25Feb

[AS 3] Fullscreen Mode with a Stage Area ContextMenu()

5 comments so far

To follow up with a previous demo of the Fullscreen capabilities, there has been a request to allow for Fullscreen mode when the user simply clicks within the Flash stage area. I wrote up a new document class that would allow this, but with limitations based on the Flash Player vs. AIR applications.

Based on the DisplayState property there are 3 available values:

  1. StageDisplayState.FULL_SCREEN Sets AIR application or Flash Player to expand the stage over the user’s entire screen, with keyboard input disabled.
  2. StageDisplayState.FULL_SCREEN_INTERACTIVE Sets the AIR application to expand the stage over the user’s entire screen, with keyboard input allowed. (Not available for content running in Flash Player.)
  3. StageDisplayState.NORMAL Sets the player back to the standard stage display mode.

I guess the only convcern for any non-AIR application would be the value of StageDisplayState.FULL_SCREEN_INTERACTIVE.

Further documentation can be found here: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/
flash/display/Stage.html#displayState

package {
	import flash.display.Sprite;
	import flash.display.StageDisplayState;
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuItem;
	import flash.events.ContextMenuEvent;
    import flash.ui.ContextMenuBuiltInItems;
    import flash.text.TextField;

    public class FullScreenStage extends Sprite {
        private var myContextMenu:ContextMenu;

        public function FullScreenStage() {
            myContextMenu = new ContextMenu();
            removeDefaultItems();
            addCustomMenuItems();
            this.contextMenu = myContextMenu;

            addChild(createLabel());
        }

        private function removeDefaultItems():void {
            myContextMenu.hideBuiltInItems();

            var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
            defaultItems.print = true;
        }

        private function addCustomMenuItems():void {
			// add the full screen item
			var fs:ContextMenuItem = new ContextMenuItem("Go Full Screen" );
			fs.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onShowFullScreen);
			myContextMenu.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);
			myContextMenu.customItems.push( xfs );
        }

		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 createLabel():TextField {
			var txtField:TextField = new TextField();
            txtField.text = "Right Click The Stage Area";
            txtField.x = 0;
            txtField.y = 0;
			txtField.width = stage.stageWidth;
            return txtField;
        }
    }
}

Share/Save/Bookmark

Categories: Actionscript 3

Monday, February 25th, 2008 at 5:49 am and is filed under Actionscript 3. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

5 Responses to “[AS 3] Fullscreen Mode with a Stage Area ContextMenu()”

  1. Posted by Deane Nettles 24th June, 2008 at 4:53 am

    Thank you for the explanation of FULL_SCREEN vs. FULL_SCREEN_INTERACTIVE.
    My question is, I’ve tried to call FULL_SCREEN with scripts other than yours. I’ve tried to add a simple “skip” button, but the call to FULL_SCREEN seems to completely disable any buttons. Is there a way to script it so that buttons become available again? Or is the way you’ve written yours make that a non-issue?

  2. Posted by admin 24th June, 2008 at 6:34 am

    Hi Deane, I honestly haven’t played with the full screen functionality other than what is here. I will be happy to try and figure out what the issue is though, are the buttons within the movie disabled? Or, are the menu items disabling?

  3. Posted by Sarina 31st July, 2008 at 1:57 pm

    Hey, how can I inport this package to a new .fla?
    Save it as an .as or? I’m a total noob.

  4. Posted by admin 1st August, 2008 at 4:35 am

    for this demo you will need to save the code as “FullScreenStage.as”, then if you are using Flash CS3, in the properties panel you will need to add “FullScreenStage” as your Main Document Class file, then publish your file (making sure that your .fla movie and the .as file are in the same directory).

    morgan

  5. Posted by Casey 2nd November, 2008 at 2:42 am

    Thanks a lot for this.

Leave a reply