AS3 Button Class

This class has been updated and a new post has been made, click here for that post.

Also known as “Developing a Pure AS3 GUI – Part 2 (buttons)”

Buttons are extremely important in a GUI. Buttons don’t have to be fancy to be useful, they just have to execute some function when clicked. Although, seeing as this is a button class for AS3 and AS3 is the language of Flash and Flash is by it’s namesake, “flashy,” this class is somewhat “fancy” beyond the utility of a simple button. Don’t be discouraged if you’re looking for an easy implementation, by no means is this class complicated, it just goes further than binding a Sprite to a function using a CLICK event listener…

My button class requires three images to function: an “up” image [the default resting image], an “over” image [the image shown on mouse over] and a “down” image [the image shown when clicked upon]. After creating the three images and placing them in some directory next to your .fla you can instantiate the button by giving it an array consisting of three image paths that lead to your images. Additional parameters are a function to be performed on click and whether or not the button is a toggle button.


var myButton:button = new button(new Array("image1.png", "image2.png", "image3.png"), onClick, false);

function onClick():void
     trace("button has been clicked");

And that’s it. If you’d like the button to run in toggle mode just pass true as the third parameter.

button Class Source Code

Tags: , , ,

5 Responses to “AS3 Button Class”

  1. You package requires your ‘raster’ util package. it is not included in the download. FYI.

  2. Ah, thanks – I’ve taken out the Raster dependencies.

  3. Why not just use the Button class?

  4. If you use a 3rd party editor like I do [TextMate] then you might know how much of a pain it is to concoct a system of embedding flash/flex components. I really like the ease of importing a class and on-demand loading some shopped png’s for my buttons. I do agree that the built-in button class is great for having many of the same button type with different labels, but it’s implementation is difficult with TextMate and FCSH. Rolling my own was faster in the end.

  5. [...] › Schell’s Code Blog » Blog Archive » AS3 Button Class Says: August 25th, 2008 at 1:07 pm [...]

Leave a Reply

Follow me on GitHub
Follow me on Google+
Follow me on Twitter
EFNX is proudly powered by WordPress
Entries (RSS) and Comments (RSS).