• AS3 判断双击事件


    //双击事件触发的时候不触发单击事件

    package { import com.greensock.TweenLite; import flash.display.DisplayObjectContainer; import flash.display.Sprite; import flash.events.MouseEvent; import flash.utils.getTimer; public class Test1 extends Sprite { private var _rect:Sprite; public function Test1() { trace("hello world"); // this.stage.addEventListener(MouseEvent.CLICK, __onTraceClick); drawRect(); _rect.addEventListener(MouseEvent.ROLL_OVER, __onOver); _rect.addEventListener(MouseEvent.ROLL_OUT, __onOut); _rect.addEventListener(MouseEvent.MOUSE_DOWN, __onDown); } private function __onOver(evt:MouseEvent):void { //trace("over"); } private function __onOut(evt:MouseEvent):void { //trace("out"); } private var _preDownTime:int = 0; private function __onDown(evt:MouseEvent):void { trace("down"); TweenLite.killDelayedCallsTo(doClick); _rect.addEventListener(MouseEvent.MOUSE_UP, __onUp); _rect.startDrag(); _preDownTime = getTimer(); } private const UP_INTER:int = 300; private var _preUpTime:int = 0; private function __onUp(evt:MouseEvent):void { trace("up"); _rect.removeEventListener(MouseEvent.MOUSE_UP, __onUp); _rect.stopDrag(); var now:int = getTimer(); if((now - _preUpTime) < UP_INTER) { trace("----double click"); } else if((now - _preDownTime) < UP_INTER) { TweenLite.delayedCall(0.2, doClick); } else { trace("drag"); } _preUpTime = now; } private function doClick():void { trace("----click"); } private function __onTraceClick(evt:MouseEvent):void { var str:String = ""; trace(printTrace(evt.target as DisplayObjectContainer)); } private function printTrace(sp:DisplayObjectContainer):String { if(null == sp) { return ""; } else { return sp.toString() + "/" + printTrace(sp.parent); } } private function drawRect():void { var rect:Sprite = new Sprite(); // red rect, starting at point 50, 50 rect.graphics.beginFill(0xFF0000); rect.graphics.moveTo(50, 50); rect.graphics.lineTo(150,50); rect.graphics.lineTo(150,150); rect.graphics.lineTo(50,150); rect.graphics.endFill(); _rect = rect; this.addChild(_rect); } } }

      

  • 相关阅读:
    delphi 字符串查找替换函数 转
    Delphi流的操作
    【BZOJ1316】树上的询问 点分治+set
    【BZOJ2406】矩阵 二分+有上下界的可行流
    【BZOJ1853/2393】[Scoi2010]幸运数字/Cirno的完美算数教室 DFS+容斥
    【BZOJ4999】This Problem Is Too Simple! 离线+树状数组+LCA
    【BZOJ2427】[HAOI2010]软件安装 Tarjan+树形背包
    【BZOJ3217】ALOEXT 替罪羊树+Trie树
    【BZOJ1336】[Balkan2002]Alien最小圆覆盖 随机增量法
    【BZOJ3435】[Wc2014]紫荆花之恋 替罪点分树+SBT
  • 原文地址:https://www.cnblogs.com/as3lib/p/3870482.html
Copyright © 2020-2023  润新知