Tareq Ibrahim
Tareq Ibrahim

Reputation: 365

Actionscript3 static variables inside functions

Can i do this in actionscript 3? counter should be defined only one time when calling timer function

function timer(e:TimerEvent):void
{
    static var counter=1;
    trace("Times: " + counter );
}

Upvotes: 1

Views: 66

Answers (1)

Ivan Chernykh
Ivan Chernykh

Reputation: 42186

What about:

function timer(e:TimerEvent):void
{
    this.counter = this.counter || 0;
    this.counter ++;
    trace("Times: " + this.counter );
}

Upvotes: 0

Related Questions