当我按住按钮不到2秒时,按钮2将会出现,或者在我按下它超过2秒后按钮3将出现,我是动作脚本3中的新手,我需要一些指南。
我的代码是
bt_1.addEventListener(MouseEvent.CLICK, onClick);
bt_1.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
bt_1.addEventListener(MouseEvent.MOUSE_UP, onUp);
var test1:Number = 0;
var test2:Number = 0;
var test3:Number = 0;
var test4:Number = 0;
function onClick(e:MouseEvent=null):void
{
test1 = getTimer();
}
function onDown(e:MouseEvent=null):void
{
test2 = getTimer();
}
function onUp(e:MouseEvent=null):void
{
// here i need to calculate the mouse down time so i can show my other button
// if mouse button pressed less than 2 seconds the bt_2 will show up.
//else bt_3 will show up.
}
答案 0 :(得分:1)
函数getTimer()返回应用程序启动时的时间(以毫秒为单位)。要测量一段时间,您要记录开始时刻getTimer(),然后从结束时刻getTimer()中减去它。
function onUp(e:MouseEvent=null):void
{
if (getTimer() - test2 < 2000)
{
btn_2.visible = true;
}
else
{
btn_3.visible = true;
}
}