/* Swipe Event
Swiping the stage executes a function containing your custom code. You can use this event to scroll text in a TextField or change states in your application.
Instructions:
1. Add your custom code on a new line after the lines that say "// Start your custom code" below.
*/
Multitouch.inputMode = MultitouchInputMode.GESTURE;
Rec_mc.addEventListener(TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler);
function fl_SwipeHandler(event:TransformGestureEvent):void
{
switch(event.offsetX)
{
// swiped right
case 1:
{
// Start your custom code
// This example code moves the selected object 20 pixels to the right.
Rec_mc.x += 20;
trace("swipe right");
// End your custom code
break;
}
// swiped left
case -1:
{
// Start your custom code
// This example code moves the selected object 20 pixels to the left.
Rec_mc.x -= 20;
trace("swipe left");
// End your custom code
break;
}
}
switch(event.offsetY)
{
// swiped down
case 1:
{
// Start your custom code
// This example code moves the selected object 20 pixels down.
Rec_mc.y += 20;
trace("swipe down");
// End your custom code
break;
}
// swiped up
case -1:
{
// Start your custom code
// This example code moves the selected object 20 pixels up.
Rec_mc.y -= 20;
trace("swipe up");
// End your custom code
break;
}
}
}
手势事件不会在位于舞台上的特定 MC 中定位,因为手势可能会占用整个屏幕或传感器的尺寸。因此,成为一名优秀的程序员,将侦听器注册到 stage
,并根据应用程序的当前状态解析手势。
if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE,init);
function init(e:Event=null):void {
removeEventListener(Event.ADDED_TO_STAGE,init);
stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler);
}