In this step by step tutorial you will learn how to create a very simple counter with a reset button, using Flash CS5 and Action Script 2.
Go to File - New and create a new document using Action Script 2.
Select the Text Tool (T), and click on the scene to create a new text field.
On the right side, select the Text Type to Dynamic Text.
Set the Paragraph Behavior to Single Line.
Set the Variable Name to "counter".
Near Family Font, select "Embed..." button and be sure to select Numberals (0..9).
Now we need to create a button to increase the counter's value.
To do that, select the Rectangle Primitive Tool (R).
Now select the Text Tool (T) and write a white text over and inside the button. Just write "Press Me" and don't forget to set the type as Static Text.
Select both objects, rectangle and text, right click on them and select Convert to Symbol (F8).
Select the Type to Button.
Great, now select the First Frame from Layer 1 and right click and open Actions Panel (F9). You need to declare the "counter" variable as number, and set it 0 (zero).
var counter:Number = new Number();
counter = 0;
Select the button you recently created on the scene, and again right click and open Actions Panel (F9). To make the counter functional you need to increase it's value every time with 1. See the code below:
Perfect now you are done with the counter! The missing thing is the reset button.
Just repeat the same steps to create a button as you did for "Press Me" button, only change the text, and put the following code:
counter = 0;
If this tutorial was useful, you can help me maintain this website with more tutorials by buying me a coffe (or at least the sugar).