Cannot make an if statement with a public variable. (AS3)

26 Views Asked by At

I am currently trying to create a script in adobe animate, that would make a certain animation play inside a symbol, when a public variable named "kill" would reach 1. The variable would've been increased, when a separate button was pressed. This was working fine, until I started to make an if statement inside that symbol. This if statement was:

if (kill == 1);
{
    play();
}

When I go to test this movie, it comes out with "Error 1176". I am still very new to AS3, so I do not know what that is. If anybody knows a solution, please help!

P.S A previous error message told me to write:

var kill = 1;

in a seperate event. Just saying if that could be a problem.

1

There are 1 best solutions below

0
Michael On

Without seeing the complete code I'm just guessing here but I see 2 issues with the code you have posted.

Firstly you have a semi colon at the end of your if statement, it should read:

if (kill == 1)
{
    play();
}

Secondly, remove the var in your event handler. var kill will define a new local variable in the scope of your event handler and won't change the state of your global variable. I'm assuming you have defined the kill variable somewhere at the top level of your script, so in your handler you should just reference it directly i.e.:

kill = 1;