I am trying to do a simple swipe motion in AS3 (action script 3). When I run the test through Android 3.6 I get no errors - but nothing happens. The box doesn't move at all. Here's the code I am using...
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.events.TransformGestureEvent;
Multitouch.inputMode = MultitouchInputMode.GESTURE;
//Side Menu Swipe
smenu_mc.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onSwipe);
//Top Menu Swipe
tmenu_mc.addEventListener(TransformGestureEvent.GESTURE_SWIPE, downSwipe);
function onSwipe (e:TransformGestureEvent):void{
if (e.offsetX == 1){
//Menu can only swipe to the right
smenu_mc.x += 278;
}
}
function downSwipe (e:TransformGestureEvent):void{
if (e.offsetY == 1){
//Menu can only swipe down
tmenu_mc.y += 99;
}
}
Does anyone know the issue? Thanks for the help!
Most likely, you issue has to do with focus.
For your code to work, the objects you've attached the SWIPE listeners to have to have the current focus to receive the event. If they are off-screen or the user doesn't touch them before swiping, they won't dispatch the event.
Try adding your listeners to the stage
instead, that way the event will always fire no matter where the swipe started.
//Global Swipe
stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onSwipe);
To slide your menus, it's very easing when using a tweening library (like TweenLite for example)
import com.greensock.TweenLite;
import com.greensock.easing.Quad;
import com.greensock.easing.Bounce;
function slideTopMenuIn(){
TweenLite.to(tmenu_mc,2,{y: 0, ease: Bounce.easeOut});
}
function slideTopMenuOut(){
TweenLite.to(tmenu_mc,1,{y: -tmenu_mc.height, ease: Ease.easeIn});
}
function slideSideMenuIn(){
TweenLite.to(smenu_mc,2,{x: 0, ease: Bounce.easeOut});
}
function slideSideMenuOut(){
TweenLite.to(smenu_mc,1,{x: -smenu_mc.width, ease: Ease.easeIn});
}
function downSwipe (e:TransformGestureEvent):void{
if (e.offsetY == 1){
slideTopMenuIn();
}
if(e.offsetY == -1){
slideTopMenuOut();
}
if (e.offsetX == 1){
slideSideMenuIn();
}
if(e.offsetX == -1){
slideSideMenuOut();
}
}