Preventing the right mouse cheat in your Flash games
Filed Under Actionscript 2, Flash, Game design, Tutorials • 19 Comments
Today I played the millionth mouse avoider Flash game… Shirk!
I am a real pro at mouse avoider games… look how easily I beat the hard level.
Watch the video!
What a champion…
This happens because you can right click the mouse, showing the menu.
As far as I know, you can’t prevent the menu to show, but you can detect when the player presses the right mouse button.
Just insert into your code, in a place that will be executed every frame, this script:
1 2 3 | if (ASnative(800, 2)(2)) {
// code to execute when the player tries to cheat
} |
What is that ASnative function?
It’s an undocumented function used mainly by component developers. You can find some examples at Open Source Flash
Since the documented mouse handlers only detect left mouse button, we need to use this function to do the trick.
But remember this function is undocumented and therefore unsupported.
Moreover, there is no guarantee future versions will support it or work with it
But at the moment it seems to work, and that’s enough.
They can be easily customized to meet the unique requirements of your project.
19 Responses to “Preventing the right mouse cheat in your Flash games”
Leave a Reply
- Get up to $100,000 for your next Flash game with Mochi GAME Developer Fund
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines – 17 lines version
- Sell sitelocked version of your Flash games and even .fla sources to Free Online Games
- Protect your work from ActionScript code theft with SWF Protector
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines
- Understanding Box2D’s one-way platforms, aka CLOUDS
- Triqui MochiAds Arcade plugin for WordPress upgraded to 1.2
- Box2D Flash game creation tutorial – part 2
- 11 Flash isometric engines you can use in your games
- Monetize your Flash games with GamesChart
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 1
- Create a Flash Racing Game Tutorial
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash draw game like Line Rider or others - part 1
- Triqui MochiAds Arcade plugin for WordPress official page
- Create a flash artillery game - step 1
- Flash game creation tutorial – part 5.2 (4.88/5)
- Create a flash artillery game – step 1 (4.79/5)
- Create a Flash Racing Game Tutorial (4.76/5)
- Create a flash artillery game – step 2 (4.74/5)
- Create a survival horror game in Flash tutorial – part 1 (4.73/5)
- Creation of a Flash arcade site using WordPress – step 2 (4.73/5)
- Flash game creation tutorial – part 2 (4.71/5)
- Flash game creation tutorial – part 1 (4.70/5)
- Create a flash draw game like Line Rider or others – part 1 (4.69/5)
- Creation of a platform game with Flash – step 2 (4.68/5)

(9 votes, average: 4.33 out of 5)





Why not use
if(Key.isDown(2)){
//Cheat code
}
This is VERY helpful.
it’s the same, but ASnative is more “obfuscated”
Hah! Nice one, I’ve never seen or known about that ‘hack’ to be honest; I was only aware of the old Tab trick (which is obviously killed by putting all your code on one frame like you always recommend).
I don’t see how you could possibly beat those levels without that hack, lol.
Hi Emanuele,
did u read this:
http://www.einternals.com/blog/web-development/flashflex/disable-right-click-menu-in-flash
yes plam4u, but you need javascript too, and when you publish your games in the portals, they won’t add any JS script
This won’t trigger on a Mac though. Only on PC (and perhaps Linux, never tried that).
I think this is a well used cheat in flash games but your missing the cleverness of the developer.
If he knows the code to change the right click menu then he can probably put in an anti cheat too. But he specifically kept it in so more users can link back to his site.
@Michael: there is also code somewhere to disable the inbuilt flash “tab” feature rather than detecting when the user presses tab. I remember reading it somewhere.
I knew about the Key.isDown(Key(2)) one already. I think that may be more effective. Good find anyways, though.
well, the key(2) is less effective because that only detects if the right click button was pressed. What if someone had a tablet pc and there are no right click buttons? All they have to do is hold down the stylus until it right clicks… how can u detect that with key(2)? I havent tested it, but still Emanuele’s way is much more effective.
Solution: Don’t do mouse avoider games. They suck.
you can change what the right click says and take the clicker toa certain slide.
Just put:
function go () {
gotoAndStop(19);
}
var myMenu:ContextMenu = new ContextMenu();
myMenu.hideBuiltInItems();
var cheat1:ContextMenuItem = new ContextMenuItem(“Click here for money”, go);
var cheat2:ContextMenuItem = new ContextMenuItem(“Cheat at the lottery!”, go);
var cheat3:ContextMenuItem = new ContextMenuItem(“Free pie”, go);
var cheat4:ContextMenuItem = new ContextMenuItem(“Click here to cheat”, go);
var cheat5:ContextMenuItem = new ContextMenuItem(“Cheating is for NOOBS!”, go);
var cheat6:ContextMenuItem = new ContextMenuItem(“Cheating is for gays”, go);
var cheat7:ContextMenuItem = new ContextMenuItem(“Please don’t cheat”, go);
var cheat8:ContextMenuItem = new ContextMenuItem(“CHEAT!!!”, go);
myMenu.customItems.push(cheat1, cheat2, cheat3, cheat4, cheat5, cheat6, cheat7, cheat8);
_root.menu = myMenu;
you can change what it says by changing the bit where it says stuff like “CHEAT!!!”
it is very usefull.
Well, you could simply put in some code that will say “You’re cheating!” and restart the game if you press the left mouse button. Simply, if you right-click you have to left click to switch off the menu and continue playing…
Does anyone know how to do this in AS3?
Wonderful!
Just needed this to fix a cheat on my latest game!
There is a way to do this using ActionScript 3.0:
stage.addEventListener(Event.MOUSE_LEAVE, func);
function func (event:Event):void
{
//the code inside this function will be triggered when the mouse leaved the stage or when the contextual menu (right-click) is triggered
}
the AS3 solution posted above does not work… i have a client the is going above and beyond requesting to have this for there game. first we never promised it, because if people want to cheat at a game… well then what is the point. people have cheated since the contra game and everyone i am sure remembers that cheat code to get 30 xtra men.
regardless, i would love to see an AS3 solution for this i have search high and low and found nothing that will meet the need.
-aj
I would check the location of the movieclip object instead of the mouse x/y position for collision. Then, the right-click cheat shown in that video would actually make you lose.
Josh is right, you shouldn’t check the mouse position.
Instead update xpos/ypos variables from the mouse position on mouse movements and check against those.
Once you right click the variables don’t get updated and you collide.