如何识别特定区域的滑动手势?

时间:2013-09-22 20:36:55

标签: actionscript-3 air gesture

我正在使用Air Android应用程序,我想根据用户手势显示和隐藏菜单。 如何将手势识别设置到特定区域而不是整个舞台? (例如从y 0到100 px的区域)

Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE , onSwipe); 

function onSwipe (e:TransformGestureEvent):void{
if (e.offsetY == 1) { 
 //User swiped towards bottom
showMenu()
 }
 else if (e.offsetY == -1) { 
 //User swiped towards top
hideMenu()
 } 
}

1 个答案:

答案 0 :(得分:0)

您应该使用适当的尺寸和位置向舞台添加一个组件(空的精灵容器让我们称之为mySprite),然后您有两个选项:

选项1

http://www.republicofcode.com/tutorials/flash/as3swipegesture/

选项2

添加一项检查以查看是否在mySprite上完成了滑动

function onSwipe (e:TransformGestureEvent):void{\
**if (e.target=!mySprite){return}**
if (e.offsetY == 1) { 
 //User swiped towards bottom
showMenu()
 }
 else if (e.offsetY == -1) { 
 //User swiped towards top
hideMenu()
 } 
}

选项3

Multitouch.inputMode = MultitouchInputMode.GESTURE;

var mySprite = new Sprite();
mySprite.addEventListener(TransformGestureEvent.GESTURE_SWIPE , onSwipe);
mySprite.graphics.beginFill(0x336699);
mySprite.graphics.drawRect(0, 0, 100, 80);
var myTextField = new TextField();
myTextField.y = 200;
addChild(mySprite);
addChild(myTextField);

function onSwipe(evt:TransformGestureEvent):void {

    if (evt.offsetX == 1 ) {
    myTextField.text = "right";
    }
    if (evt.offsetY == -1) {
    myTextField.text = "up";
    }
    myTextField.text = evt.phase;

}