AS3 Quickie – MouseEvent.RELEASE_OUTSIDE

With Flash Player 11.3 and above, the ability to detect a mouse release outside of embedded Flash content makes a triumphant return! Missing in ActionScript 3.0 from Flash Player 9 onward, crafty developers have come up with some strange hacks to compensate for the missing event – but with the modern Flash Player runtime such trickery is no longer needed :)


Requires Flash Player 11.3 or above!

To get this working only takes a few steps in your ActionScript code. Everything relies upon classes that already exist - such as flash.events.MouseEvent, but you must target Flash Player 11.3 or above.

Perform the necessary imports:

import flash.events.MouseEvent;

We then simply need to assign an event listener to our Stage, listening for the new RELEASE_OUTSIDE event:

stage.addEventListener(MouseEvent.RELEASE_OUTSIDE, onMouseReleaseOutside);

And follow through with a method to handle the event, itself:

private function onMouseReleaseOutside(e:MouseEvent):void {
	//do something amazing
}

To see this working, click anywhere upon the Stage and drag the mouse cursor off past the edge of the Stage and the release. In the embedded example above, you will see the status message update to reflect this.

The full code is below. Note that the FLA contains upon the Stage a TextField with the instance ID of statusField:

package  {
	
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class ReleaseMouseOutside extends MovieClip {
		
		public var statusField:TextField;
		
		public function ReleaseMouseOutside() {
			this.addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void {
			stage.addEventListener(MouseEvent.RELEASE_OUTSIDE, onMouseReleaseOutside);
		}
		
		private function onMouseReleaseOutside(e:MouseEvent):void {
			statusField.appendText("\nMouse Released! (outside)");
		}
		
	}
	
}

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

Need to update Flash Professional to support a newer version of the runtime? Chris Griffith has a great step-by-step rundown on how to do it.

3 comments

  1. Releasing outside the stage was never a problem. This will work with MouseEvent.MOUSE_UP just fine from the stage object. The advantages of having MouseEvent.RELEASE_OUTSIDE is that 1) you don’t need to depend on the stage (and thusly won’t have to worry about cleaning up your listener references there) and 2) you don’t have to write code to distinguish an up from an up outside since it has its own event now.

Comments are closed.