Thursday, 24 September 2009

Button components in Actionscript 3

In this tutorial you will learn how to use the button component in Actionscript 3.0. A button component is rectangular button which can be pushed with the mouse to perform actions. The button component voids you having to create you own custom button in Flash. Below I will show a simple example of how to use the button component.

Button components in Actionscript 3.0

Step 1

Open a new Flash AS3 file.
Select Windows > Components and drag two Button components on the stage. Then open up the component inspector (Windows > Component Inspector), and change the labels to ‘button 1’ and ‘button 2’ accordingly.

Step 2

Select each button in turn and give the following instance names respectively: button1_btn and button2_btn.

Step 3

On the timeline insert a new layer called ‘Actions’ then open up the Actions panel and enter the following code:

//hit1 & 2 boolean variables.
var hit1:Boolean=false;
var hit2:Boolean=false;

//Mouse click listeners for the buttons.
button1_btn.addEventListener(MouseEvent.CLICK, button1Click);
button2_btn.addEventListener(MouseEvent.CLICK, button2Click);

//Disables button when clicked and enables the other button.
function button1Click(event:MouseEvent):void {
if (hit1) {

//Disables button when clicked and enables the other button.
function button2Click(event:MouseEvent):void {
if (hit2) {

Step 4

Test your Button components Ctrl + Enter. Now try pressing the buttons and you should notice one of the button disabled when you click it.

You should now be able to use button components in Actionscript 3.0. Checkout part 2.


Suta 24 September 2009 at 19:09  

Lol. That's cool. And very fun to play with. Keep up with the tutorials! They're very helpful to newbs of AS3 like me.

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP