user3694232
user3694232

Reputation: 1

If conditional is changing a variable in AS3

Complete beginner to AS3 here, but I have tried to create a countdown, that when reaches 0 goes to the next frame. I attempted this by stopping on the frame as soon as it was entered and then the countdown started. It worked without the if statement but as soon as i insert the if statement it starts counting down from 0 seconds instead of 15.

stop()

var countdown:Number = 15;

var fl_CountDownTimerInstance:Timer = new Timer(1000, countdown);
fl_CountDownTimerInstance.addEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler);
fl_CountDownTimerInstance.start();

function fl_CountDownTimerHandler(event:TimerEvent):void
{
    trace(countdown + " seconds");
    countdown--;
}

if (countdown=0){


play();
}

Thanks in advance

Upvotes: 0

Views: 53

Answers (1)

Yaroslav Valiev
Yaroslav Valiev

Reputation: 161

Use

if (countdown==0){

Because if you use one =, you changing value

countdown == 0 // checks if countdown is equals 0

countdown = 0 //  assigns 0 value to countdown 

Upvotes: 2

Related Questions