1

我正在开发一个需要滑出面板和触摸事件的 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           
}
4

1 回答 1

2

是的。

这段代码应该可以帮助你。它可能超出您的需要,但它有效。:) 取自Adob​​e 网站:

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; 
}
于 2013-05-16T23:56:39.410 回答