As3 identifies double-click events

Source: Internet
Author: User
// Double-click the event to trigger the click event.

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, 50rect.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);}}}

  

As3 identifies double-click events

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.