Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import flash.utils.Timer;
  4.     import flash.display.Sprite;
  5.     import flash.events.Event;
  6.     import flash.events.MouseEvent;
  7.     import flash.events.TimerEvent;
  8.    
  9.     public class Main extends Sprite
  10.     {
  11.         protected var timer:Timer;
  12.         private static const CLICK_DELAY:int        = 200;
  13.        
  14.         public function Main()
  15.         {
  16.             timer           = new Timer(CLICK_DELAY, 1);
  17.             timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
  18.            
  19.             stage.addEventListener(MouseEvent.CLICK, clickHandler);
  20.         }
  21.        
  22.         function clickHandler(event:MouseEvent):void
  23.         {
  24.             timer.start();
  25.             stage.addEventListener(MouseEvent.CLICK, doubleClickHandler);
  26.             stage.removeEventListener(MouseEvent.CLICK, clickHandler);
  27.         }
  28.  
  29.         function doubleClickHandler(event:MouseEvent):void
  30.         {
  31.             trace("double click");
  32.             resetClicks();
  33.         }
  34.  
  35.         function singleClickHandler():void
  36.         {
  37.             trace("single click");
  38.             resetClicks();
  39.         }
  40.  
  41.         function timerHandler(event:TimerEvent):void
  42.         {
  43.             singleClickHandler();
  44.         }
  45.        
  46.         function resetClicks():void
  47.         {
  48.             try {
  49.                 timer.reset();
  50.                 stage.removeEventListener(MouseEvent.CLICK, doubleClickHandler);
  51.             } catch(e:Error){}
  52.             stage.addEventListener(MouseEvent.CLICK, clickHandler);
  53.         }
  54.     }
  55.    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement