How to create an enum in ActionScript 3.

August 5, 2009 at 7:48 pm (ActionScript 3.0) (, , , , )

Hello folks.

Some of us face the issue on how to create an enum in ActionScript 3. It’s no big deal, really!

    public final class ToolType
        public static const PEN:ToolType = new ToolType();
        public static const ZOOM:ToolType = new ToolType();
        public static const BRUSH:ToolType = new ToolType();

As you can see, I’ve created a class named ToolType, I gave it the attribute final as there’s no need to extend the class (unless you wanted some kind of mutated enumerator ;-)).

Each variable is an instance of the class, so that its restricted to the enumeration data type.

That way I can easily do the following:

var toolType:ToolType;
toolType = ToolType.BRUSH;

if (toolType == ToolType.BRUSH)
    trace("You have brush selected.");

There are many other ways to create enumerations in ActionScript. Here’s a link to Adobe on enumerations:


Permalink Leave a Comment

My first post on WordPress.

August 5, 2009 at 7:20 pm (Uncategorized)

Hello world.

This is my first post, as the title of this post says.

I’ll be making posts ranging from many different topics, such as C#, C/C++, ActionScript 3, OpenGL and more!

Feel free to leave any comments behind.


Permalink 1 Comment