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.
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