This code ends up with error 1084...

Subscribe to This code ends up with error 1084... 5 posts, 3 voices

Sign in to reply


 
avatar for POKEMONMASTER260 POKEMONMASTE... 58 posts
Flag Post

…expecting identifier before plusassign (On var Score; += 20;).

Here’s the code:

function btn1_Click(myevent:MouseEvent): void {
var Score; += 20;
gotoAndStop(2);
}

btn_btn.addEventListener(MouseEvent.CLICK,btn1_Click);
}

btn_btn.addEventListener(MouseEvent.CLICK,btn1_Click);

 
avatar for POKEMONMASTER260 POKEMONMASTE... 58 posts
Flag Post

Woops, here’s the code correctly:

function btn1_Click(myevent:MouseEvent): void {
var Score; += 20;
gotoAndStop(2);
}

btn_btn.addEventListener(MouseEvent.CLICK,btn1_Click);

 
avatar for iCheese iCheese 198 posts
Flag Post

Get rid of the semi-colon after “var Score”.
Also, have the “var Score” part outside of the function, and have it say “Score += 20” in the function.

 
avatar for ssjskipp ssjskipp 170 posts
Flag Post

Here’s why iCheese is right:
“var” declares a variable. Since you’re declaring, you can’t plusassign (+=) since it’d be adding a null/undefined value.
Second, a semicolon means the end of a line in AS, so you essentially wrote:
var Score;
+= 20;

Make sense? You have to declare a variable first, set it to a value, then manipulate it.

 
avatar for iCheese iCheese 198 posts
Flag Post

Also, by putting the declaration of a variable in a function, it means that it only exists in that function, so you won’t be able to use it anywhere else.

Sign in to reply


Click Here