2012-07-07 64 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