HOWTO: Using the ContextMenu in AS3 with FullScreen Mode As a Sample

Right clicking and other mouse support in flash is not really a shining star but in AS2/AS3 you *can* stuff the context menu with items. You can clear out all but Settings and About from the menu and stuff in other items that may pertain to a selected movieclip or the entire app you are building. This can be good when adding multiple functions into applications and for extra functions that you want to make available from a quick location such as full screen, selecting an item etc.

To enable a context menu for full screen capabilities take this example:

1) Make your document class of your AS3 Flash CS3 file to the class below.

package
{
import flash.display.*;
import flash.errors.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;
import flash.net.*;
import flash.media.*;
import flash.ui.*;
import flash.utils.*;
import flash.xml.*;
public class FullScreenTest extends MovieClip
{
public function FullScreenTest()
{
// create the context menu, remove the built-in items,
// and add our custom items
var fullscreenCM:ContextMenu = new ContextMenu();
fullscreenCM.addEventListener(ContextMenuEvent.MENU_SELECT, onContextMenuHandler);
fullscreenCM.hideBuiltInItems();
var fs:ContextMenuItem = new ContextMenuItem("Show Full Screen" );
fs.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onShowFullScreen);
fullscreenCM.customItems.push( fs );
var xfs:ContextMenuItem = new ContextMenuItem("Exit Full Screen");
xfs.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onShowNormalScreen);
fullscreenCM.customItems.push( xfs );

// THIS ASSUMES YOU HAVE A MOVIECLIP IN THE LIBRARY
// THAT IS SET TO A CLASS NAMED 'mc' that inherits from MovieClip
var m:MovieClip = new mc();
m.contextMenu = fullscreenCM;
addChild(m);
}
// functions to enter and leave full screen mode
function onShowFullScreen(event:ContextMenuEvent):void
{
stage.displayState = StageDisplayState.FULL_SCREEN;
}
function onShowNormalScreen(event:ContextMenuEvent):void
{
stage.displayState = StageDisplayState.NORMAL;
}
// function to enable and disable the context menu items,
// based on what mode we are in.
function onContextMenuHandler(event:ContextMenuEvent):void
{
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
}
}
}
}

2) Now Export to HTML and be sure to change the exported parameters in the HTML file to allowFullScreen = true (for the fullscreen effect) and menu = true (for the ability to add in context menu items) to whatever library you use for embedding flash:

   'menu', 'true',
   'allowFullScreen', 'true'

OR if using HTML parameters

<param name="allowFullScreen" value="true" />
<param name="menu" value="true" />

You can view a sample here. (right click on the movie clip and ‘show full screen’, then ‘hide full screen’)

You can download a sample FlashCS3/AS3 version here.

If you want more information on fullscreen check here and here (downloadable sample and component).

Advertisements

8 Responses to “HOWTO: Using the ContextMenu in AS3 with FullScreen Mode As a Sample”

  1. percy Says:

    maravilloso, hace dias que uso el flash cs3 y no comprendia bien en modo full screen haciendo uso del menu, gracias por tu trabajo, me ayuda mucho.

  2. Disabling the context menu in as3.. | The Musings Of A Newman Says:

    […] http://drawlogic.com/2007/06/12/howto-using-the-contextmenu-in-as3-with-fullscreen-mode-as-a-sample… By Andrew Posted in as3 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. « Now i’m not American but… […]

  3. Marcus Says:

    Hello everyone,

    That´s pretty cool sample of how to use the contextmenu in AS3, but i like to know how apply the context for the entire stage, like this _root.menu = fullscreenCM; (AS2 Version)

    Thanks

  4. matt Says:

    in the document class

    (this as MovieClip).contextMenu =

    MaTT

  5. proogounk Says:

    I read some of the posts and I think it is a great blog. What do you think of my inviting responsiveness I have a joke for you =) What do termites do to relax? Take a coffee table break!!

  6. site de rencontres absolument gratuit Says:

    If some one needs to be updated with hottest technologies afterward he must be pay a visit this website and be up to date daily.

  7. CLICK HERE! Says:

    Hello there! I know this is kinda off topic
    buut I was wondering which blog platform are you using for this website?
    I’m getting tired of WordPress because I’ve had issues with hackers
    and I’m looking at options for another platform.
    I would be fantastic if you could point me in the direction of a good
    platform.

  8. http://www.Youtube.com/watch?v=-keuzkmXT_c Says:

    I always emailed this weblog post page to all my
    contacts, because if like to read it next my friends will too.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: