Preventing the right mouse cheat in your Flash games
Posted by Emanuele Feronato on 05/10/08 in Actionscript 2, Flash, Game design, Tutorials
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:
-
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.
If you liked this post buy me a beer (or two) » Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.They can be easily customized to meet the unique requirements of your project.
tag this
RJ | May 10, 2008 | Reply
Why not use
if(Key.isDown(2)){
//Cheat code
}
Gabriel Bianconi | May 10, 2008 | Reply
This is VERY helpful.
Emanuele Feronato | May 10, 2008 | Reply
it’s the same, but ASnative is more “obfuscated”
Michael | May 11, 2008 | Reply
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.
plam4u | May 11, 2008 | Reply
Hi Emanuele,
did u read this:
http://www.einternals.com/blog/web-development/flashflex/disable-right-click-menu-in-flash
Emanuele Feronato | May 11, 2008 | Reply
yes plam4u, but you need javascript too, and when you publish your games in the portals, they won’t add any JS script
Viktor Hesselbom | May 11, 2008 | Reply
This won’t trigger on a Mac though. Only on PC (and perhaps Linux, never tried that).
James Prankard | May 11, 2008 | Reply
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.
Shadow Scythe | May 12, 2008 | Reply
I knew about the Key.isDown(Key(2)) one already. I think that may be more effective. Good find anyways, though.
Kesh | May 12, 2008 | Reply
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.
Mike | May 12, 2008 | Reply
Solution: Don’t do mouse avoider games. They suck.
lewis | May 12, 2008 | Reply
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.