长按事件和短按事件的实现 Flash as3.0

舞台上有一个动态文本框(txtTime)和一个按钮(btnOnClick)

 

import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;

var timeNum=1;    //默认时间是01;
txtTime.text="0"+timeNum;

var timer:Timer;
var delay:Number=1000;
btnOnClick.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
btnOnClick.addEventListener(MouseEvent.MOUSE_UP,onUp);
 
function onDown(e:MouseEvent):void
{
    timer = new Timer(delay,1); //超过1秒就算是长按
    timer.addEventListener(TimerEvent.TIMER,onTimer);
    timer.start();
}

var tm:Timer = new Timer(100, 0);
function onTimer(e:TimerEvent):void
{  
 tm.start();
 tm.addEventListener(TimerEvent.TIMER, timerListener);
    timer.removeEventListener(TimerEvent.TIMER,onTimer);
}
function timerListener(e:TimerEvent):void
{
 timeNum++;
 txtTime.text=timeNum;

你可能感兴趣的:(timer,function,Flash,UP,import,delay)