2012-07-07 66 views
1

我有一個簡單的按鈕,我想做出一些轉變。
如果當前幀是1我要玩幀2
如果當前幀是2我要玩框架3
如果當前幀爲3我要玩框架1.
爲什麼我的腳本不在ActionScript 3.0中工作?謝謝。ActionScript 3的按鈕,如果設置currentFrame

buton1.addEventListener(MouseEvent.CLICK, buton1Click); 

function buton1Click(event:MouseEvent):void{ 
    if(currentFrame == 1){ 
     gotoAndStop(2); 
    } 
    if(currentFrame == 2){ 
     gotoAndStop(3); 
    } 
    if(currentFrame == 3){ 
     gotoAndStop(1); 
    } 
} 
+0

'buton1.addEventListener(MouseEvent.CLICK,buton1Click);如果(當前幀== 1){ \t gotoAndPlay(2); \t} \t else if(currentFrame == 2){ \t gotoAndPlay(3); (當前幀== 3){ \t gotoAndPlay(1); \t} } ' – CBuzatu 2012-07-07 17:50:30

+0

當您點擊按鈕時會發生什麼?你有沒有試過添加一些'trace()'語句並運行調試器來查看你的代碼在做什麼? – 2012-07-07 20:27:10

回答

2

if塊總是如此 - 你移動到下一幀,比測試,如果你這個框架上。

鑑於您的按鈕涵蓋時間表,就像這樣:

timeline

您的代碼將是:

stop(); 

button1.addEventListener(MouseEvent.CLICK, button1Click); 

function button1Click(event:MouseEvent):void 
{ 
    switch (currentFrame) 
    { 
     case 1: 
      gotoAndStop(2); 
      break; 
     case 2: 
      gotoAndStop(3); 
      break; 
     case 3: 
      gotoAndStop(1); 
      break; 
    } 
} 
+0

非常感謝你! – CBuzatu 2012-07-08 02:16:51

1
stop(); 
stage.addEventListener(MouseEvent.CLICK, button1Click); 

function button1Click(event:MouseEvent):void { 
    this.gotoAndStop((this.currentFrame % this.totalFrames) + 1); 
} 

//this way you can change the timeline without changing code