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




Enumerations in Actionscript 3

5 11 2009

Coming from a .Net sort of background, when typing in ‘enum’ into an Actionscript 3 file, I was baffled when it didn’t turn blue! Enumerations are such useful things, I was surprised they weren’t supported in every programming language!

However in Actionscript 3 there is a way to create a class that mimics an enumeration using static constant variables. The code is as follows:

public class CountryCode
{
    public static const UK:int = 1;
    public static const US:int = 3;
    public static const AUS:int = 4;
}

You can then access the “enumeration” as normal:

var whichCountry:int = CountryCode.UK;