AS3 onReleaseOutside
January 25th, 2008
It seems to be that the ReleaseOutside we all know from Actionscript 2 is no more in AS3. Why? I don’t know. I noticed allot of people having problems with this lack of feature. The work around has been published all over the web, another reference here will help spread the word. The idea of an onReleaseOutside MouseEvent is that you detect if the mouse is not over the object when it is up. So what you simply need to do is relocate the MouseEvent.MOUSE_UP from the object you want to detect to the stage. So what does this look like?
// constructor public function MyClass() { //we use this event to obtain the stage object addEventListener(Event.ADDED_TO_STAGE, onAdded); } // stage object is now available private function onAdded(e:Event):void { addChild(_yourbutton); _yourbutton.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); } private function onMouseDown(me:MouseEvent):void { trace("mouse down"); stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp) } private function onMouseUp(me:MouseEvent):void { trace("mouse up"); stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp) }
I hope you find this useful.
Filed under Actionscript 3, Flash, Flex |Leave a Reply