Create Simple Counter in Flash with Actionscript 2

Posted on March 6, 2013 in Flash Category with Easy Difficulty

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.

Step 1 - Document Settings

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

Create a Simple Counter in Flash

Near Family Font, select "Embed..." button and be sure to select Numberals (0..9).


Step 2 - Draw a Button

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.


Step 3 - Convert to Symbol

Select both objects, rectangle and text, right click on them and select Convert to Symbol (F8).

Select the Type to Button.


Step 4 - Set the Counter Variable to Zero

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;

Step 5 - Increment Value for Counter Variable

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:

on(press) {

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:

on(press) {
counter = 0;


Final Results

Download Files

Related Articles
  1. Christoffer says:

    Hi Dan! Thanks for the tutorial.

    I have a similar click counter but I would like it to count down as well. When I’m coming down to 0 and goes minus 1 I would like to have a minus sign infront of the number. Any ideas?

    • Hi Christoffer,

      You can add the decremental operator on another button (see the sample below) and don’t forget to set the Embed Settings for your text field, like I did in Step 1.

      on(press) {

  2. Joel says:

    How would you write a simple ‘if’ condition for the counter value.

    For example if the counter reached 10 to goto a certain frame?


    • Hello Joel,

      Here is an example for this tutorial, with the same variable:

      if (counter == 10) {
           _root.gotoAndPlay(2); // where 2 is the frame number or name with quotes
Hint: Wrap your code syntax (html, css or others) between <pre> and </pre> tags. All comments are moderated.

four − = 1

Subscribe by E-mail

HTML-TUTS is built under the mighty WordPress platform.