2016-07-23 62 views
1

我正在開發一個在Adobe空氣中的遊戲,其中我有一個影片剪輯在中心。當用戶觸摸此影片剪輯並在舞臺上移動時,影片剪輯需要相應地將其「x」更改爲觸摸位置。我使用下面的代碼,這是做什麼打算做的事:
移動影片剪輯,而用戶不斷觸摸它AS3

MC.addEventListener(TouchEvent.TOUCH_MOVE, touchDownMC); 
function touchDownMC(e:TouchEvent):void { 
    MC.x = e.stageX; 
} 

的MC正確移動,但問題是,10-15秒後,當用戶按下MC和移動在它周圍,MC只是停止響應當前的觸摸事件,並且用戶需要重新觸摸它並移回來。它似乎是失去了TouchEvent。我如何讓MC一直移動,只要我有手指就可以,讓它保持傾聽和移動?

回答

3

找到解決方案!這樣做的最好方法是使用此代碼,我發現在SO AS3/AIR check if TouchPhase.ENDED is over object

這是我是如何實現它在我的情況:

MC.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin); 
function onTouchBegin(event:TouchEvent) { 
    if(touchMoveID != 0) { 
    //  myTextField.text = "already moving. ignoring new touch";  
    trace("It Did Not"); 
    return; 
    } 
    touchMoveID = event.touchPointID; 

// myTextField.text = "touch begin" + event.touchPointID; 
    stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove); 
    stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd); 
} 
function onTouchMove(event:TouchEvent) { 
    if(event.touchPointID != touchMoveID) { 
    // myTextField.text = "ignoring unrelated touch"; 
     return; 
    } 
    MC.x = event.stageX; 
    MC.y = event.stageY; 
// myTextField.text = "touch move" + event.touchPointID; 
} 
function onTouchEnd(event:TouchEvent) { 
    if(event.touchPointID != touchMoveID) { 
    //  myTextField.text = "ignoring unrelated touch end"; 
     return; 
    } 
    touchMoveID = 0; 
    stage.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove); 
    stage.removeEventListener(TouchEvent.TOUCH_END, onTouchEnd); 
    // myTextField.text = "touch end" + event.touchPointID; 
}