Jalapeno Jack
Jalapeno Jack

Reputation: 410

Flash Actionscript 3 Simple Counter

I am struggling to make a simple flash actionscript 3 counter in a text field, that starts at the beginning of my animation at 0, and increases with each frame.

This will count up until it reaches a particular frame on the timeline, where I would like the number to begin doubling instead of counting up.

I can only seem to find AS2 examples, and i'm not too sure how to get the double part working. Can anyone out there help me?

Thanks in advance!

Upvotes: 0

Views: 6961

Answers (1)

golyo
golyo

Reputation: 518

I'm guessing you are using Flash CS and you are putting your code directly on the frames, so this snippet on the first frame should work.

Let's say you have a TextField on your stage with an instance name of counterTextField, and you want the count to start doubling up at frame 100.

import flash.events.Event;

var count:int = 0;
var limit:int = 100;
var increase:int = 1;
stage.addEventListener(Event.ENTER_FRAME, countFrames);

function countFrames(e:Event):void
{
    if (count <= limit)
    {
         count += increase;
    }
    else
    {
         count *= 2;
    }
    counterTextField.text = String(count);
}

Upvotes: 2

Related Questions