contact

Posts Tagged ‘events’

onReleaseOutside in Actionscript 3

Thursday, January 29th, 2009

actionscript 3 does not nativly support a onReleaseOutside Event. When creating things like a scrollBar or other UI elements this can be quite annoying.

Here is a simple work around that uses a simple movieClip as a button:

import flash.display.MovieClip
 import flash.events.*

var myBtn:MovieClip=new MovieClip()
 myBtn.graphics.beginFill(0x003366,1)
 myBtn.graphics.drawRect(0,0,50,50)
 addChild(myBtn)
 myBtn.addEventListener(MouseEvent.MOUSE_DOWN,downHandler)

function downHandler(event:MouseEvent):void{
 stage.addEventListener(MouseEvent.MOUSE_UP,upHandler)
 trace("mouse went down")
 }
 function upHandler(e:MouseEvent):void{
 if(e.target==stage){ // this checks to see if the event is coming from the stage or not
 stage.removeEventListener(MouseEvent.MOUSE_UP,upHandler)
 trace("mouse went up outside")
 }else{
 trace("mouse went up")
 }
 }

pretty simple :-)

heres the fla for download