MouseUpOutside in ActionScript 3

20 07 2010

I recently needed an event that detected a mouse up outside of my object. It used to exist in ActionScript 1 & 2 as onReleaseOutside and although ActionScript 3 has MouseDownOutside and MouseWheelOutside, for some reason there is no MouseUpOutisde. Pretty silly if you ask me!

So after a little searching, I found a post that had some code that worked perfectly for me. I adapted mine a little, but first the original post. It is the fourth post on the page, you could just do a quick search on the page for “Detecting a mouseUp Outside” if you wanted to save your scrolly finger 🙂 For the original post, click here.

My slightly modified code is in a Flex Builder 3 project. I added the “clicked” variable as an application variable so I can access it from anywhere. The function is needed to detect when a scroll bar is being clicked and released so I added the MouseEvent.MOUSE_UP event to my module (this.addEventListener etc) on creationComplete.

public function captureMouseUp(e:MouseEvent):void
{
if(e.eventPhase == EventPhase.BUBBLING_PHASE)
return;
if(Application.application.clicked == ctgScroller)
{
Application.application.clicked = null;
var target:Sprite = e.target as Sprite;
if(target == ctgScroller) //mouse was released over the scroll bar
{
ScrollBarUp();
}
else
{
ScrollBarUp(); //mouse was released outside the scroll bar
}
}
}

Thanks again to the original post that helped me out with this which can be found HERE.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: