2014-02-07 48 views
0

我有一個功能,我需要點擊和立方體一次,立方體將旋轉到那邊,然後當我點擊並按住2秒將進入第五頁或當我點擊沒有保持將開始旋轉的立方體。Actionscript 3定時器點擊保持

這是我

var numPressed:Number = 0 
    function side6(event:MouseEvent):void { 
     numPressed++; 
      if (numPressed % 2) { 
       SimpleZSorter.sortClips(container); 
       TweenLite.to(container, 1, {rotationX:-8,rotationY:193}); 
       addEventListener(Event.ENTER_FRAME, rotateStop); 
       removeEventListener(Event.ENTER_FRAME, rotateThis); 
      }else if (NEED SOEMTHING HERE TO DETECT MOSUE HOLD AFTER SECONDS) { 
       gotoAndStop(5); 
      } 
      else{ 
       addEventListener(Event.ENTER_FRAME, rotateThis); 
      } 
    } 

的想法ATM是numpressed計算,如果印刷機是奇數或偶數,這意味着1次點擊將停止立方體旋轉,2將再次啓動,第三個會停止,如果等等,我需要這樣保持那樣的表演。

我需要在第二條if語句中的東西,除了讓它在拿着鼠標上工作之外,一切都很好。

任何幫助表示讚賞

伊恩

回答

0

我會建議使用此MouseEvent.DOWNMouseEvent.UP和存儲Date.time

EG:這組函數將跟蹤MouseEvent.DOWN和MouseEvent.UP事件之間經過的毫秒數量。

private var mouseDownTime:Number = NaN,mouseUpTime:Number = NaN; 

private function init():void 
{ 
    yourCubeObject.addEventListener(MouseEvent.DOWN,onMouseDown); 
    yourCubeObject.addEventListener(MouseEvent.UP,onMouseUp); 
    yourCubeObject.addEventListener(MouseEvent.OUT,onMouseOut); 
} 
private function onMouseOut(event:MouseEvent):void 
{ 
    mouseDownTime = mouseUpTime = NaN;//clear storage 
} 
private function onMouseDown(event:MouseEvent):void 
{ 
    mouseDownTime = new Date().time;//store system time in milliseconds since epoc 
} 
private function onMouseUp(event:MouseEvent):void 
{ 
    mouseUpTime = new Date().time; 
    if (!isNaN(mouseDownTime))//avoid error case where mouse went down outside object 
    { 
     if ((mouseUpTime - mouseDownTime) >= 2000) 
     { 
      //mouse held down for more the 2 seconds, your function here. 
     } 
    } 
    onMouseOut(event);//reset counters 
} 
相關問題