AS3 / AIR检查,如果TouchPhase.ENDED超过对象(AS3/AIR check i

2019-10-18 03:30发布

我正在开发一款iOS / Android应用程序,需要滑出面板和触摸事件。 是否有可能获得如果用户触摸的对象,但随后释放掉的对象?

var touch:Touch = e.getTouch(this);
if(touch.phase == TouchPhase.BEGAN)
{
    trace("Tab toggle begin");
}
if(touch.phase == TouchPhase.ENDED)
{
    //If not over object do something           
}

Answer 1:

是的。

此代码应该帮助你。 这可能是比你更需要的,但它的工作原理。 从:)摘自Adobe官方网站:

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT; 
var mySprite:Sprite = new Sprite(); 
mySprite.graphics.beginFill(0x336699); 
mySprite.graphics.drawRect(0,0,40,40); 
addChild(mySprite); 
var myTextField:TextField = new TextField(); 
addChild(myTextField); 
myTextField.width = 200; 
myTextField.height = 20; 
var touchMoveID:int = 0; 

mySprite.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin); 
function onTouchBegin(event:TouchEvent) { 
    if(touchMoveID != 0) { 
        myTextField.text = "already moving. ignoring new touch";     
        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; 
    } 
    mySprite.x = event.stageX; 
    mySprite.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; 
}


文章来源: AS3/AIR check if TouchPhase.ENDED is over object