Aug 04 2009
[AS3] Hiding the Built-In ContextMenu Items
UPDATE: You may also refer to Hiding the Built-In Native MenuBar (And ContextMenu Items).
In my opinion, the native right-click context menu is an odd legacy from the Flash Movies days. It may be useful when Flash is used as a video player, for animations and cartoons, in the absence of any proper custom UI.
If you are developing Flash applications, you should consider always hiding the native right-click Flash Player context menu’s built-in items. Sure, you cannot get rid of the context menu completely, but you should at least hide the built-in items. It makes the application look a lot more professional because the long list of built-in items are mostly irrelevant.
If you don’t do anything about it, when end-users right-click on your Flash application, the pop-up context menu will show “Zoom In”, “Zoom Out”, “Show All”, “Quality” (and sub menu), and “Print…” – all of these should be done in-application via properly designed user interface if the application allows these features to begin with.
For example, allowing end-users to zoom in/out without designing the application to handle these adjustments properly can be detrimental to the user experience. And if your application handles zooming in/out, it should have the proper UI to convey the feature to end-users rather than depending on the right-click menu.
Likewise, “Quality” adjustment is something that should be done in-application via a proper Options dialog where graphics, sounds, and perhaps other application-specific options are made available.
For multiple-frame SWFs (such as would be the case if you have a preloader frame), the built-in context menu items will also include, in addition to those mentioned above, “Play”, “Loop”, “Rewind”, “Forward” and “Back” – none of which should be of any relevance to RIAs. Letting the end-user activate any of these frame-manipulation actions can potentially mess up your application.
HTML
You can get rid of the built-in context menu items via the HTML container page, by defining the Flash object’s “menu” parameter as “false”. If you are developing using the Adobe Flash IDE, you can generate the proper HTML page by unchecking the “Display Menu” option in the File -> Publish Settings dialog (HTML tab). If you are developing using FlashDevelop, the “menu” parameter is already set to “false” by default.
However, using this method, you are depending on the HTML container page to tell the SWF to hide the context menu’s built-in items – if the SWF is run outside the HTML page, the menu items will no longer be hidden. If you cannot guarantee that the SWF will be run within the HTML page you have generated, this method will not work well. For example, if you are developing a Flash widget whereby only the SWF itself will be distributed, the menu items will not be hidden if the SWF is ultimately shown standalone, or within a HTML page where the “menu” parameter of the Flash object is not set to “false”.
ActionScript
You can hide the built-in items of the native context menu by inserting just two lines of code:
contextMenu = new ContextMenu(); contextMenu.hideBuiltInItems();
You would typically insert the code into your top-level AS3 class as follows:
package { import flash.display.Sprite; import flash.ui.ContextMenu; public class Main extends Sprite { public function Main() { contextMenu = new ContextMenu(); contextMenu.hideBuiltInItems(); } } }
Note: the “contextMenu” property is implemented by the flash.displayObject.InteractiveObject class.
Main -> Sprite -> DisplayObjectContainer -> InteractiveObject
In the above code, you are setting the “contextMenu” property of the top-level Main class instance to a new ContextMenu instance (where the built-in items are hidden).
Using this method, the instructions are internal to the SWF itself. Whether the SWF is distributed and run standalone, or run within a HTML page, the built-in items will be hidden. Also, regardless of the value of the “menu” parameter of the containing HTML page, the built-in items are going to be hidden (ie setting the “menu” parameter to “true” in the HTML page will not override this).
With the built-in menu items hidden, when the end-user right-clicks on your Flash application, the pop-up context menu will show only two items – “Settings…” and “About Adobe Flash Player…” – concise, sleek, a lot more professional looking.








When you use FlashDevelop, and create an AIR Project, you can also use your own
Right-Click (MouseEvent.RIGHT_CLICK).
When do this, you be sure you don’t use this in a flashplayer (i have for this a config-file), because, the FlashPlayer stopped with the work when he create a Listener
(addEventListener(MouseEvent.RIGHT_CLICK, yourFunction)). (Only work when is Air)