AS3:一个Click事件侦听器上的两个操作

时间:2014-07-07 18:46:44

标签: actionscript-3 function event-handling

所以我要做的就是点击一下弹出一个菜单。现在我只想使用一个。所以在第一次点击时我需要它移动到x 130.然后在下一次点击移动到x -77。我该怎么做?我已经尝试过if语句,但这对我来说效果不佳。

function clickMove (e:MouseEvent):void{
    smenu_mc.x = 130;
    if(smenu_mc.x == 130){
        smenu_mc.x = -77;
    }
}

1 个答案:

答案 0 :(得分:2)

您目前正在做的是始终将其设置为-77。因为if语句总是为真:(见代码旁边的注释)

function clickMove (e:MouseEvent):void{
    smenu_mc.x = 130; //you're setting it to 130
    if(smenu_mc.x == 130){ //this will be true, because of the line above...
        smenu_mc.x = -77;
    }
}

您需要做的是切换值:

function clickMove (e:MouseEvent):void{
    if(smenu_mc.x < 130){ //if it's less than 130, then set it to 130, otherwise set it to -77.
        smenu_mc.x = 130;
    }else{
        smenu_mc.x = -77;
    }
}
相关问题