CUSTOM RIGHT-CLICK MENU IN AS2                                as2


    This very simple tutorial will show you how to create your own custom right-click menu for your flash projects in actionscript 2.0. This project does not require anything else but actionscript. At the you should get something like this ( just right click anywhere on the stage ):


     Open actionscript 2.0 flash document. Since we dont need anything on the stage open the actions window (F9) right away and copy in this actionscript code:

var myMenu = new ContextMenu(); 

function goToThisURL(){
	getURL("http://www.google.com", "_blank");
}
var redirection = new ContextMenuItem("URL link", goToThisURL);
myMenu.customItems.push(redirection);

function goToThisFRAME(){
	gotoAndStop(2);
}
var nextframe = new ContextMenuItem("Go To Next Frame",  goToThisFRAME);
myMenu.customItems.push(nextframe);

function splitter(){
	//you function goes here
}
var split = new ContextMenuItem("<(^_^)>",splitter);
myMenu.customItems.push(split);


function placeholder(){
	test_txt.text="Text has changed!";
}
var PH = new ContextMenuItem("© 2012 Your Company",placeholder);
myMenu.customItems.push(PH);


myMenu.hideBuiltInItems();
_root.menu = myMenu;

     First line creates new right-click menu. On line 3-7 is first custom menu item. In this case its redirection function which is assigned to redirection variable on line 6. In the brackets is displayed text and function which will be executed after this menu item is clicked. This repeates again and again on lines 9-13, 15-19 and 22-26. Each of them represents one menu item. As you can see you can customize the functions as you like. By duplicating these sections you can add more and more menu items. Line 29 hide all the default right-click menu functions like zoom in and out, play,stop etc. If you skip this line, these features will be shown along with your custom menu. And on the very last line we add our new custom menu to the default right-click menu.


DOWNLOAD SOURCE FILE