2014-07-07 41 views
0

所以我想要做的是得到一個菜單彈出點擊。現在我只想用一個。所以在第一次點擊我需要它移動到x 130.然後在下一個點擊移動到x -77。我將如何做到這一點?我已經嘗試了一條if語句,但是這對我來說並不適合。AS3:一個Click事件監聽器的兩個動作

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

發佈您的代碼。編輯:相關部分。 – Fygo

+0

您使用if語句確定菜單當前是否存在。顯示你現在使用的代碼,使菜單進入 – BadFeelingAboutThis

+0

@Fygo有if語句希望可以幫助 – Klye

回答

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; 
    } 
} 
+0

它出來,但不會返回 – Klye

+0

使用我提供的切換代碼? – BadFeelingAboutThis

+0

是的,你的代碼只是出來,但不會返回第二次點擊。剛剛看到你的新帖子現在嘗試它 – Klye