Posted by VitaminB | Posted in ActionScript, Source Downloads | Posted on 20-06-2008
Tags: ActionScript, Context Menu, Flash, Source

In this quick tutorial you can learn how to add a custom context menu to you flash content. You can add a menu to a specific MovieClip or to the whole Stage area. I will show you both methods.
1. Create a new movie in flash.
2. Create a new movieClip and give it an instance name of “context_mc”
3. Copy this code ito the first frame of your new flash document. Make sure you paste it in the frame and not on the movieclip.
//Hide the message
message_txt._visible=false;
// Assign the functions to the custom context menu
function menu1() {
getURL(“http://www.brianwiltshire.net”);
}
function menu2() {
getURL(“http://www.brianwiltshire.net/lab”);
}
function menu3() {
message_txt._visible=true;
}
function menu4() {
message_txt._visible=false;
}
// Create the menu
contextMenu = new ContextMenu();
contextMenu.hideBuiltInItems(); // hides the build-in menu items (except Settings)
// Call the functions
contextMenu.customItems.push(new ContextMenuItem(“Brian Wiltshire – Flash Website”, menu1));
contextMenu.customItems.push(new ContextMenuItem(“FlashLab – Experiments”, menu2));
contextMenu.customItems.push(new ContextMenuItem(“Show message”, menu3));
contextMenu.customItems.push(new ContextMenuItem(“Hide message”, menu4));
// associates the contextMenu with the context_mc
context_mc.menu = contextMenu;
// you can also associate the menu with the whole stage by adding
//_root.menu = contextMenu;
4.Test your movie.
It should look like this. When you right click on the movieClip you should see the custom menu. If you right click on the stage it should be the standard flash context menu. You can change this by uncommenting the last line of code. _root.menu = contextMenu
Post here if you would like the source.



Hehe, thank you, perfect addon for the video player..
Thanks..
Great thank you !!
Hi brian, I followed all the steps, but cant make it work.. Will you be able to mail me an example flash file, i would really appreciate it.. Thank you. I really like your new flash website.. my email is thierybug84@yahoo.fr Thank you again..
Cool thank you
Works fine for me, thanks.. Do you have to do that for each clip if you want a menu for that clip?
Good work, cheers!!
@ thiery I mailed you the source. Let me know how you get on with it.
Hi Brian, Thank you, got it working now. Thank you so much for sharing this..
Awesome, thank you very much