2013-02-20 88 views
0

創建按鈕並給出名稱「b」。 創建動態文本並命名爲「tampil」。 運行它...點擊b按鈕運行計時器,然後再次單擊停止(但錯誤)。不能停止此計時器

以下腳本是我修改過的一個項目。 我的問題是,我該如何停止計時器?

import flash.events.MouseEvent; 
var xx:Number = 1; 
var waktux:Timer; 
var i1:Number = 1; 
var ab:Number = 1; 
var lantaii:String = "lg"; 
b.addEventListener(MouseEvent.CLICK, stopp); 
function stopp(e:MouseEvent) 
{ 
    waktu(0,0,ab); 
    if (ab==1) 
    { 
     ab = 0; 
    } 
    else 
    { 
     ab = 1; 
    } 
} 
function waktu(e, d, cx) 
{ 
    var waktux:Timer; 
    var waktuy:Timer; 
    function sayHello(f:TimerEvent):void 
    { 
     tampil.text = String(e); 
     e = e + 1; 
    } 
    function sayHellow(e:TimerEvent):void 
    { 
     tampil.text = String(d); 
     d = d + 1; 
    } 
    function sayHello2(f:TimerEvent):void 
    { 
     tampil.text = String(e); 
     e = e + 1; 
    } 
    if (cx==1) 
    { 
     if (lantaii == "lg") 
     { 
      naek(); 
     } 
     else 
     { 
      waktuy = new Timer(400,10); 
      waktuy.addEventListener(TimerEvent.TIMER, sayHellow); 
      waktuy.start(); 
      waktuy.addEventListener(TimerEvent.TIMER_COMPLETE, naek2); 
     } 
     function naek() 
     { 
      waktux = new Timer(400,10); 
      waktux.addEventListener(TimerEvent.TIMER, sayHello); 
      waktux.start(); 
     } 
     function naek2(s:TimerEvent):void 
     { 
      waktux = new Timer(400,10); 
      waktux.addEventListener(TimerEvent.TIMER, sayHello2); 
      waktux.start(); 
     } 
    } 
    else 
    { 
     trace("nih masuk"); 
     waktux.stop(); 
     waktux.reset(); 
     waktuy.reset(); 
     waktux.removeEventListener(TimerEvent.TIMER, sayHello); 
     waktux.removeEventListener(TimerEvent.TIMER, sayHello2); 
     waktuy.removeEventListener(TimerEvent.TIMER, sayHellow); 
     waktuy.removeEventListener(TimerEvent.TIMER_COMPLETE, naek2); 
    } 
} 

回答

1

我想你重新定義了waktux在全球範圍內的一個和其他waktu功能。 刪除這些行

import flash.events.MouseEvent; 
var xx:Number = 1; 
var waktux:Timer; //<--------------------------- HERE 
var i1:Number = 1; 
var ab:Number = 1; 
var lantaii:String = "lg"; 

function waktu(e, d, cx) 
{ 
    var waktux:Timer; //<--------------------------- HERE 
    var waktuy:Timer; 
    function sayHello(f:TimerEvent):void 
    { 
     tampil.text = String(e); 
     e = e + 1; 
    } 
    function sayHellow(e:TimerEvent):void 
    { 
     tampil.text = String(d); 
     d = d + 1; 
    } 
    function sayHello2(f:TimerEvent):void 
    { 
     tampil.text = String(e); 
     e = e + 1; 
    } 
    if (cx==1) 
    { 
     if (lantaii == "lg") 
     { 
      naek(); 
     } 
     else 
     { 
      waktuy = new Timer(400,10); 
      waktuy.addEventListener(TimerEvent.TIMER, sayHellow); 
      waktuy.start(); 
      waktuy.addEventListener(TimerEvent.TIMER_COMPLETE, naek2); 
     } 
     function naek() 
     { 
      waktux = new Timer(400,10); 
      waktux.addEventListener(TimerEvent.TIMER, sayHello); 
      waktux.start(); 
     } 
     function naek2(s:TimerEvent):void 
     { 
      waktux = new Timer(400,10); 
      waktux.addEventListener(TimerEvent.TIMER, sayHello2); 
      waktux.start(); 
     } 
    } 
    else 
    { 
     trace("nih masuk"); 
     waktux.stop(); 
     waktux.reset(); 
     waktuy.reset(); 
     waktux.removeEventListener(TimerEvent.TIMER, sayHello); 
     waktux.removeEventListener(TimerEvent.TIMER, sayHello2); 
     waktuy.removeEventListener(TimerEvent.TIMER, sayHellow); 
     waktuy.removeEventListener(TimerEvent.TIMER_COMPLETE, naek2); 
    } 
} 

之一,只是爲了好玩

function stopp(e:MouseEvent) 
{ 
    waktu(0,0,ab); 
    ab = !ab; 
}