AS3 Quickie – Removing the right-click menu from Flash content

One of the great new features introduced with Flash Player 11.2 is the ability to intercept the right-click from a user’s mouse. A simple MouseEvent listener can be added to the Stage or any object which extends flash.display.InteractiveObject. Not only does this have the effect of completely removing the right-click menu from Flash content, but we can also alternatively react to the right-click in any way we choose.

[kml_flashembed publishmethod=”static” fversion=”11.2.0″ movie=”/wp-content/uploads/2012/06/AEL2012_5min.swf” width=”550″ height=”400″ targetclass=”flashmovie” play=”true” loop=”true” menu=”false” quality=”high” wmode=”direct” allowfullscreen=”true” allowscriptaccess=”always” allownetworking=”all”]
Requires Flash Player 11.2 or above!

To enable this, we must import the MouseEvent class into our project:

import flash.events.MouseEvent;

Next, let’s add a listener to the Stage itself, disabling the context menu in the process:

stage.addEventListener(MouseEvent.RIGHT_CLICK, doNothing);

In the included example, we also register a listener upon our MovieClip symbol. A right-click upon this will fire off an additional method which controls the animation:

angryFace.addEventListener(MouseEvent.RIGHT_CLICK, destroyFace);

That’s it! A pretty simple solution for a problem that Flash developers have had pretty much since Flash was Flash :)

Here is the full source code:

package  {
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.display.MovieClip;
	
	public class KillContextMenu extends Sprite {
		
		public var angryFace:MovieClip;
		
		public function KillContextMenu() {
			stage.addEventListener(MouseEvent.RIGHT_CLICK, doNothing);
			angryFace.addEventListener(MouseEvent.RIGHT_CLICK, destroyFace);
		}
		
		private function doNothing(e:MouseEvent):void {
			//do nothing...
			trace(e.type);
		}
		
		private function destroyFace(e:MouseEvent):void {
			//send to oblivion
			e.currentTarget.gotoAndPlay("Destruction");
		}
		
	}
}

Want the full package? Download below:
Packaged code and Flash Professional CS6 project

12 thoughts on “AS3 Quickie – Removing the right-click menu from Flash content”

  1. Pingback: AS3 Quickie – Removing the right-click menu from Flash content | In Flagrante Delicto! « eaflash

  2. Pingback: rechter Mausklick Event? - Flashforum

  3. Thank you for this article. I have one question : Is it possible to use this with a link on the animation. i tried but i’m not an expert an i got many error codes.

    If it is possible, please let me know how.

    Thank for your help

  4. is it possible to achive the same from AS3 in flex builder, i had a go but could not get the rigjht click
    angryFace.addEventListener(MouseEvent.RIGHT_CLICK, destroyFace)
    to work

  5. I have the RIGHT_CLICK mouse event and function for that event in main class of flash project. I create the event using stage.addEventListener(MouseEvent.RIGHT_CLICK, M2), where M2 is function which shall do something after right click. After doing this, flash right click menu gets disabled, but the function dont do anything else. Is there a way to fix it? I am using adobe flash, project flash player is 11.2.

  6. I was seeing the same issue as A3l, when running the script (including yours) in flash the function doesn’t appear to do anything, but once it’s published it works fine.

Leave a Reply to Joseph Labrecque Cancel Reply

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