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)
if(Application.application.clicked == ctgScroller)
Application.application.clicked = null;
var target:Sprite = as Sprite;
if(target == ctgScroller) //mouse was released over the scroll bar
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.

Scroll bars in Flex

13 01 2010

I’ve just been doing some work with scroll bars in Flex. I used the standard HScrollBar and set my maximumScrollPosition and minimumScrollPosition, but the thumb (the little rectangle between the two buttons) was staying a standard size. I have now found out this is because you also need to set the pageSize property. So I set this to be the same as the maximumScrollPosition property, and like magic, my thumb changes size depending on how much it has to scroll through. Excellent!

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;

Embedding fonts in Flex Builder 3 using Actionscript 3

13 10 2009

I’ve been working on something that involves me doing some work with Flex and Actionscript. I needed to place a shape on my canvas and then write some text on that shape. The text field needed to be rotated by 90 degrees. All of the following needed to be done from the Actionscript. As you may already be aware, if I were to try and do this without embedding the font, the text would disappear. The best way I eventually found of embedding an existing system font was the following:

[Embed(systemFont='Franklin Gothic Medium', fontName="Franklin Gothic Medium", mimeType="application/x-font-truetype")]
const FONT_FRANKLIN:String;

Click here to read the full post and information on this code.

To then use this code with my text field, my code was as follows…

var format1:TextFormat = new TextFormat();
format1.font = "Franklin Gothic Medium";
format1.size = 14;
format1.align = "center";
var label1:TextField = new TextField();
label1.defaultTextFormat = format1;
label1.embedFonts = true;
label1.textColor = 0xFFFFFF;
label1.autoSize = TextFieldAutoSize.CENTER;
label1.text = "Connect";
label1.rotation = 90;

It is important to remember to set embedFonts to true, otherwise the text will still disappear!