Sunday, 19 July 2009

Disable context menu in Actionscript 3

In this tutorial you will learn how to disable the right click context menu when a flash movie clips is running. The context menu by default contains the following: zoom in, 100%, show all, quality and print. The default menus could affect the overall look and flow of the Flash file created by the developer, so disabling the context menu can remove any inconveniences or problems.

You will need to use the ContextMenu class for this tutorial, more information on this class can be found at the ContextMenu AS3 component reference.


Disable context menu in Actionscript 3

Step 1

Open a new Flash AS3 file.
Select Ctrl + Enter and right click on the stage and you should see the following:



**This is the default context menu on the stage.


Step 2

Now, time to remove the default context menu. Hit F9 to open up the actions panel and enter the following code:

//1.
var my_cMenu:ContextMenu = new ContextMenu();

//2.
my_cMenu.hideBuiltInItems();

//3.
contextMenu = my_cMenu;

Code:
1. Creates an instance of the ContextMenu class with the variable name ‘my_cMenu’ which will reference the content menu.
2. The ‘hideBuiltItems’ method hides all the default items in the context menu.
3. This sets the item to the property which will hide all the menu items.


Step 3

Test the movie clip Ctrl + Enter. You should notice the default menu items have now been moved, but the items in the following image below cannot be removed.



Why not checkout the custom context menu tutorial ?

2 comments:

Mahmut 10 May 2010 11:37  

Thanks nice post

Static 13 January 2011 12:51  

Thanks for this! Helps a lot! Now my users can't press play to go to the next frame :D

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP