11-19-2010 04:08 PM
Is it possible to catch both SWIPE_START and SWIPE DOWN together? I would assume it would fire both events but it looks like it will only catch the SWIPE_START and not he SWIPE_DOWN afterwards.
package
{
import qnx.events.QNXApplicationEvent;
import qnx.system.QNXApplication;
import flash.display.Sprite;
// The following metadata specifies the size and properties of the canvas that
// this application should occupy on the BlackBerry PlayBook screen.
[SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
public class SwipeTest extends Sprite
{
private var app:QNXApplication = QNXApplication.qnxApplication;
public function SwipeTest()
{
app.addEventListener(QNXApplicationEvent.SWIPE_DO
app.addEventListener(QNXApplicationEvent.SWIPE_ST
}
private function swipeDownAction(action:QNXApplicationEvent):void{
trace("Swipe down event fired");
}
private function swipeStartAction(action:QNXApplicationEvent):void{
trace("Swipe Start Event fired");
}
}
}
They do work when only one is added but not the other is used.
Solved! Go to Solution.
11-19-2010 04:22 PM - last edited on 11-19-2010 04:27 PM
hey navikun,
what i found is that you dont really need to use the SWIPE_DOWN event... everything can be handled with the swipe start. as soon as the user touches the top bazel it sends the event SWIPE_START. Then you just create a series of eventListeners and functions to handle the finger movement. Use the following code as a guide:
package
{
import caurina.transitions.Tweener;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import qnx.events.QNXApplicationEvent;
import qnx.system.QNXApplication;
// The following metadata specifies the size and properties of the canvas that
// this application should occupy on the BlackBerry PlayBook screen.
[SWF(width="1024", height="600", backgroundColor="#F4F4F4", frameRate="30")]
public class SwipeDownTest extends Sprite
{
private var swiping:Boolean;
public function SwipeDownTest()
{
// do stuff
//listen for when the swiping starts
QNXApplication.qnxApplication.addEventListener(QNXApplicationEvent.SWIPE_START, onSwipeStart);
}
//handle the swipe
private function onSwipeStart( e:QNXApplicationEvent ):void
{
//sets the boolean to true meaning the swiping is happening
swiping = true;
//when finger moves in from bezel to on screen track the finger
addEventListener( Event.ENTER_FRAME, trackMouse );
//when the finger is lifted off screen trigger function mouseUp
stage.addEventListener( MouseEvent.MOUSE_UP, mouseUp );
}
//sample function to handle where the finger is is
private function trackMouse( e:Event ):void
{
// finger movement in the Y direction
var pos:int = stage.mouseY;
}
//handle what happens when the finger comes off screen
private function mouseUp( e:MouseEvent ):void
{
//always remember to remove listeners when not in use
removeEventListener( Event.ENTER_FRAME, trackMouse );
//when the finger is no longer swiping set to false
swiping = !swiping;
}
}
}
so you dont need to explicitly listen for the SWIPE_DOWN event just use the SWIPE_START
11-19-2010 05:31 PM
OK, I see. All I needed to do was add to your code:
stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUp);
in the mouseUp function as well so we aren't catching those anymore either
. This is actually much more flexible than just the SWIPE_DOWN. Assumming the bezel will really give those negative values. We could catch just bezel swipes with the mouseY property.
Thanks for the help.
11-19-2010 07:03 PM
haha good catch! i totally missed that
good luck!