Newest Articles

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

Popular Articles

True Fullscreen Flash Mode
Hangman Game
Infinitely Zooming Image
Mp3 Player with XML Playlist
Catapult Game
3d Rotating Image Cube

Random Articles

Glowing Orb
Bouncing Ball with Smoke Effect
Storing Data Similar to Cookies
iPod Style Wheel Slider
Alert Box


Shapes the Game
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.
Place the following code in the Actions tab on the main stage:
  1. var linkURL="";
  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. = 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