Handle the Right Click in AS3

It can not be denied that handling the Right Click in Flash is a problem.
At first, it was made to display a Contextual Menu with Flash Player’s options, this is great for a website. However Flash is also used to make browser’s games and it is reductive if we can’t use this. For example in a Point & Click game, like the mythical Diablo, the Right Click is very important and simply to use. If you want to develop that kind of game with Flash (one of my dream ;-)) it will be difficult to manage this. In this direction, old Apple’s mouses with their only click were preposterous !! I think that was a commercial argument like “our Operating Systems is so ergonomic that you don’t need an alternative button”. But if you used software like Photoshop, you will always push the ctrl button on the keyboard, but also shift for other action or alt, cmd…

So today I try to look over that. And what I notice is :
– the right click and the middle click are functional in AS3 (those MouseEvent exist) but work only for Air !!
– you can easily change the context menu options (good example) and add functions but About and Settings can not be removed from the menu !!
– use JavaScript to handle the Right Click thanks to this class. Here we go :

I created a .swf in which with a right click you create a circle, and with a left click on a circle delete it (the application). Note it seems it is no more updated. But what happens ? It doesn’t work with Safari and Opera… failed. And you should have notice that I created a circle by pressing the right button, logically it should be the left… ?? Because of the JavaScript, you can’t give an occurence through it to Flash, so how can I obtain the target ?
This is the code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var circle:Circle;
 
stage.addEventListener(MouseEvent.MOUSE_DOWN, deleteCircle);
 
var i:int = 0;
 
var methodName:String = "rightClick";
var method:Function = rightClick;
ExternalInterface.addCallback(methodName, method);
 
function rightClick():void {
 
	circle = new Circle();
	i++;
	circle.name = String(i);
	addChild(circle);
	circle.x = mouseX;
	circle.y = mouseY;
}
 
function deleteCircle(m:MouseEvent):void {
 
	if (m.target.name != null) {
		removeChild(getChildByName(m.target.name));
	}
}

So to conclude, at the moment you can’t use cleanly the right click in Flash like the left. You will always have the contextual menu with About and Settings’ buttons. But in fact who use them ? Aside on a website using Webcam or Microphone. So I think that developers should have the choice if they want a contextual menu (by default if we don’t need the right click) or not to have a more ergonomical application.

Leave a Reply

Your email address will not be published. Required fields are marked *