Cliff White
Cliff White

Reputation: 1

Cannot get "else/if" statement to execute on button click in ActionScript 2

I cannot figure out why the "else/if" statement never executes. Can anyone explain why this code in ActionScript 2 does not work? I have a button on the stage with an instance name of "numb". I'm trying to get the button to change positions on the screen upon a mouse click on the button and then return to it's original position on a second mouse click on the button. The first click on the button works as it should, but the second click on the button does nothing nor do any subsequent clicks on the button. For some reason, the 'else if' statement is not functioning, but I don't know why. Thanks for any help you can provide. Here is the ActionScript 2 code I'm using. The code is attached to the button "numb".

on(press) {     
    if (numb._x == 150.1) { 
    numb._x = 677.0;    //move to position x1
        numb._y = 271.1;   //move to position y1
    trace(numb._x);      //track position x1
    trace(numb._y);     //track position y1
}
else if (numb._x == 677.0) { 
    numb._x = 150.1;   // return to original x position
    numb._y = 542.1;  // return to original y position
}
}

Upvotes: 0

Views: 32

Answers (1)

mtv1337
mtv1337

Reputation: 1

you write this code in a button, why don't you use _root, or even better if you just do

yourButton.onRelease = function (){
    if (numb._x == 150.1) { 
        numb._x = 677.0;    //move to position x1
            numb._y = 271.1;   //move to position y1
        trace(numb._x);      //track position x1
        trace(numb._y);     //track position y1
    }
    else if (numb._x == 677.0) { 
        numb._x = 150.1;   // return to original x position
        numb._y = 542.1;  // return to original y position
    }
}

Upvotes: 0

Related Questions