创建按钮并命名为“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);
}
}