views:

551

answers:

4

Hey there, I'm creating a simple click and scroll for a future menu for my personal site. I have a box, I called it thing_mc, and I have 3 positions for it. I have a next and prev. button that will control thing_mc position. I'm using TweenLite to animate thing_mc, if that makes a difference.

I get a 1083 error (...else is unexpected) and (...rightparen is unexpected).

Can anyone tell me why and how I can resolve this?

Thanks

    import gs.TweenLite;

next_mc.addEventListener(MouseEvent.CLICK, nextListener);
prev_mc.addEventListener(MouseEvent.CLICK, prevListener);

//prev_mc.visible = false;

function nextListener(event:MouseEvent):void
{
    if(thing_mc.x == 400);
    {
    TweenLite.to(thing_mc, .5, {x:50, y:50});
    }
    else if //// i get error 1083 here (...else is unexpected)
    {
    TweenLite.to(thing_mc, .5, {x:-100, y:50}); //// i get error 1083 here (...rightparen is unexpected)
    }
}

function prevListener(event:MouseEvent):void
{
    if(thing_mc.x == -100);
    {
    TweenLite.to(thing_mc, .5, {x:400, y:50});
    }
    else if //// i get error 1083 here (...else is unexpected)
    {
    TweenLite.to(thing_mc, .5, {x:500, y:50}); //// i get error 1083 here (...rightparen is unexpected)
    }
}   

next_mc.buttonMode = true;
prev_mc.buttonMode = true;
A: 
else if //// i get error 1083 here (...else is unexpected)

You have a few options here. You can either use a second condition, if you want to use else if i.e.

else if (someCondition) { ...

or, use just else

else { ...

or use another if

if { ...

It all depends on what you want to achieve.

From what I can see, the second option (plain else) looks like what you want.

dirkgently
Hey thanks for the quick reply.I went with else{that worked!
DwayneG
+3  A: 

I am not AS expert, but the semicolon after if(thing_mc.x == 400); and if(thing_mc.x == -100); seems strange. Should rather read if(thing_mc.x == 400) and if(thing_mc.x == -100) I'd say.

Max
Hey thanks for the quick reply.I removed those strange semicolons and combined with the help above, it worked!!
DwayneG
So please mark this answer as "accepted" by clicking the big checkmark next to the number on the left.
Glenn
A: 
function nextListener(event:MouseEvent):void
{
    if(thing_mc.x == 400);
    {

Don't use ; after the if brackets ;-)

kajyr
A: 

Wats going on is the parser sees if ( cond ) ;

as if ( cond ) /empty statement/ ; //semicolon ends empty statement

(and the else if /.../ of course lacked the parenthesized conditional expr that an if requiress).

I've seen this semicolon related error a lot. It may be because semicolons are optional in some cases in as3.

pete