Jump to content

AS3 Error 1083: Syntax error: else is unexpected NEED HELP


shulungu

Recommended Posts

I am having trouble figuring out this code


b2.addEventListener(MouseEvent.CLICK,b2handler);

function b2handler(event:MouseEvent){


if(currentFrame>=0 && currentFrame<=50){gotoAndPlay(50)}

else

if(currentFrame>=51 && currentFrame<=115){gotoAndPlay(115)}

else

if(currentFrame>=116 && currentFrame<=180){gotoAndPlay}(180)}

else

if(currentFrame>=181 && currentFrame<=195){gotoAndPlay}(50)}


}


And it shows the error, "Error 1083: Syntax error: else is unexpected" Can anybody help?
Link to comment
Share on other sites

What language is this? If it's ActionScript, which it kind of looks like, I think you might be missing quite a few semi colons. Though I've never really used it so can't speak for certain about the syntax. Also, which of these lines produces the error?

 

 

gotoAndPlay(50);
...
gotoAndPlay(115);
...

And so on.

Link to comment
Share on other sites

@Pas

 

What language is this? If it's ActionScript, which it kind of looks like, I think you might be missing quite a few semi colons. Though I've never really used it so can't speak for certain about the syntax. Also, which of these lines produces the error?

 

 

gotoAndPlay(50);
...
gotoAndPlay(115);
...

And so on.

Its ActionScript and its:

 

 

 

else (this line pops up as an error)
if(currentFrame>=51 && currentFrame<=115){gotoAndPlay(115)}
else (this line pops up as an error)
if(currentFrame>=116 && currentFrame<=180){gotoAndPlay}(180)}
else
Link to comment
Share on other sites

Right, after having had a look at it again, in peace and quiet, I've come up with a few ideas you might want to try. Again, I've never used ActionScript, so what I say might very well be wrong.

 

In the 116-180 and 181-195 if statements, the call to gotoAndPlay() has an added curly bracket between the function name and the parentheses.

 

 

gotoAndPlay}(180)
// should perhaps be
gotoAndPlay(180)

 

Also, I'm fairly sure you need to end your statements with a semi-colon. With these two things in mind, try this and see if it works (separated the lines a bit for clarity)

 

 

 
b2.addEventListener(MouseEvent.CLICK,b2handler);
function b2handler(event:MouseEvent) {
   if(currentFrame>=0 && currentFrame<=50) {
      gotoAndPlay(50);     // added semi-colon
   }
   else if(currentFrame>=51 && currentFrame<=115) {
      gotoAndPlay(115);     // added semi-colon
   }
   else if(currentFrame>=116 && currentFrame<=180) {
      gotoAndPlay(180);     // added semi-colon, removed curly bracket
   }
   else if(currentFrame>=181 && currentFrame<=195) {
      gotoAndPlay(50);     // added semi-colon, removed curly bracket
   }
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.