How to Disable the Right Click Menu in Flash
The right click menu in flash has some nice options on it, however it also allows for easy cheating in many types of games. By disabling the right click menu you can stop that cheating, and ensure your flash game is played the way it was meant to be. In this tutorial, I’ll be teaching you the actionscript 2 you need to disable the right click menu. With this code you will be able to get rid of the cheating options in flash’s right click menu, and even add a link back to your site.
First, I’ll explain why you should get rid of those extra features in flash’s right click menu. Options such as forward and back will allow players to skip around the frames in your game. It’s easy to see how this could become a problem in games with multiple levels or rooms to unlock, where all the levels are on separate frames. Players could just move from frame to frame by using the right click menu, instead of taking the time to play your game as they should.
Now that you know why you should get rid of the right click menu, it’s time to learn how to do it. Here’s the actionscript 2 code:
var rightClick:ContextMenu = new ContextMenu();//create a new right click menu called rightClick rightClick.hideBuiltInItems();//hide the built in options of the right click menu _root.menu = rightClick;//make the neccesary changes to the right click menu
That’s nice if you just want to stop cheaters, but suppose you want to add a link to your site in the right click menu. Here’s what your new code would look like:
function mySiteLink () {//add a new function called mySiteLink getURL("http://freelanceflashgames.com/news/", "_blank");//create a new window and go to FreelanceFlashGames.com/News/ }//end function var rightClick:ContextMenu = new ContextMenu();//create a new right click menu called rightClick rightClick.hideBuiltInItems();//hide the built in options of the right click menu _root.menu = rightClick;//make the neccesary changes to the right click menu var mySiteLink:ContextMenuItem = new ContextMenuItem("FreelanceFlashGames", mySiteLink);//create a custom right click tab that goes to your site when clicked. rightClick.customItems.push(mySiteLink);//put the custom right click tab into the right click menu
Now you can stop those cheaters and even put in a link back to your site, all from the right click menu.
Related posts:
April 8th, 2009 at 11:48 am
Right click is not much of a problem. For example in maze games, all you have to do is detect left clicks. When you left click to get out of the right click menu, the click is detected, no matter if you were holding left button before or not. So just detect that.
April 8th, 2009 at 2:00 pm
That’s good advice Dino, and sounds like it would work well for maze games. This tutorial is more general in getting rid of the right click menu. It can be applied to a lot of different game types.
I was more targeting games where you would have a different frame for each level rather than just maze games. The player could cheat by just clicking forward on each level, allowing them to bypass levels without completing them.
July 12th, 2009 at 11:26 pm
Very well done how to! Got the job done perfectly.
July 13th, 2009 at 2:25 pm
Thanks Vamplair, glad you liked it. :)
July 28th, 2009 at 1:42 am
I want to disable right click in flash8 through action script2.0 .If any budy who know thise answer please post me the answer
July 28th, 2009 at 9:10 am
Are you looking to disable it completely Suraj? What’s the game design aspect of your game that requires this?
November 1st, 2009 at 9:09 pm
this worked beautifully but….how do i get rid of key controls such as enter(play) and ctrl+->(forward)?
November 6th, 2009 at 11:58 am
Cool! How can we set it to always “Show All” (Not zoom in or zoom out)?
November 21st, 2009 at 6:05 am
hey um theres this problem in the most basic flash game which is a simple mouse game that requires the user not to touch the walls and reach the finish line! sadly it cannot be played fairly when some1 RIGHT CLICKS and then move his mouse to the finish line. so how to prevent something like that?
February 9th, 2010 at 12:57 pm
Very nice, but if you dont want to add your own menu and just stop cheaters there is a much easier way.
Go to the first frame of you flash and type in the following code:
fscommand(“showmenu”, “false”);
Simple as that…
February 10th, 2010 at 10:34 am
How would that work Devonsfridge? I tried testing it in Flash, but couldn’t get showmenu to show up as code.
February 14th, 2010 at 1:03 pm
i want to get rid of it completly so nothing shows when i right-click im making a maze game Plz help
April 20th, 2010 at 10:21 am
Thanks for writing this post. Now everything is clear for me.
July 4th, 2010 at 12:04 pm
can anybody kill the displaying menu completely..i’m getting uneasy on seeing “setting” and “about flash player” on right click. plz help
June 11th, 2011 at 11:05 pm
Okay, to stop the right-click mouse cheating… you just put the following code on a movieclip:
onClipEvent(enterFrame){
if(Key.isDown(2)){
_root.gotoAndStop(whateverframenumberkillsthem);
}
}
October 11th, 2011 at 4:45 pm
I’m trying to figure out a way not only to disable the menu, but also if possible I would like to actually make an action in the game happen when you right click. I’m trying to create an RPG and spells would be right click. (hopefully) if anyone has any creative ideas that would help.
June 9th, 2013 at 10:53 am
You guys are way over my head. I want to get rid of the menu completely. I don’t game (anymore)and the Flash Menu is doing naughty things to my Logitech Setpoint.
June 9th, 2013 at 10:56 am
Unless of course, somebody has a copy of Wolfenstein, Doom or Duke Nukem.lol