Newest Articles

MegaCombs
Flash Media Player
XML Driven Pie Chart
Base Defender
Hangman Game
8 Ball Pool


Popular Articles

True Fullscreen Flash Mode
Catapult Game
Hangman Game
Infinitely Zooming Image
3d Rotating Image Cube
Base Defender


Random Articles

LED Text Scroller
Alert Box
Flash Media Player
Mouse Following Preloader
Krypto Movie Quotes
Spark Effect


Links

Shapes the Game
Reddit
Newgrounds
TWiT
Link to SwfSpot
Swf Spot

Contact me on Google+



rss feed

Custom Right Click Menu

Custom Right Click Menu
AddThis Social Bookmark Button
Description: Change flash's default right-click menu using actionscript.
Author: John Bezanis
Added: January 21st 2007
Version: Flash 8


Changing the right click menu is simple and takes only a few lines of code.
actionsframe
Place the following code in the Actions tab on the main stage:
  1. var linkURL="http://www.bezzmedia.com";
  2. var linkText="Link Text";
  3. //Defines a new right-click menu
  4. var myMenu = new ContextMenu();
  5. //goToThisURL is a function that gets run whenever the link is clicked
  6. function goToThisURL(){
  7.   //_blank opens the link in a new window
  8.   getURL(linkURL, "_blank");
  9. }
  10. //Create a new item for the new menu.
  11. var copyright = new ContextMenuItem(linkText, goToThisURL);
  12. //Add the item to the new menu
  13. myMenu.customItems.push(copyright);
  14. //Hide flash's built in items (zoom in, zoom out, etc)
  15. myMenu.hideBuiltInItems();
  16. //Apply the new menu
  17. _root.menu = myMenu;
Additional items can be added to menu by adding in a few lines just before the last line.
  1. function someFunctionName(){
  2.   //_self opens the link in the same window
  3.   getURL(linkURL, "_self");
  4. }
  5. var menuItem = new ContextMenuItem("Some More Link Text", someFunctionName);
  6. //Add the item to the menu
  7. myMenu.customItems.push(menuItem);
Menu items can perform tasks other than redirecting the browser. Simply place the actionscript you'd like to run inside of the function and the code will execute when the menu item is clicked. The provided example has a function which draws a line at a random location.

Download Source File
Comments Currently Disabled