Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Adobe AIR Development

Reply
Developer
navikun
Posts: 32
Registered: 11-19-2010
My Carrier: Verizon
Accepted Solution

SWIPE_START and SWIPE_DOWN together not firing correctly

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_DOWN, swipeDownAction);
            app.addEventListener(QNXApplicationEvent.SWIPE_START, swipeStartAction);
        }
        
        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.

Please use plain text.
Developer
JRab
Posts: 2,387
Registered: 11-04-2010

Re: SWIPE_START and SWIPE_DOWN together not firing correctly

[ Edited ]

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

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Developer
navikun
Posts: 32
Registered: 11-19-2010
My Carrier: Verizon

Re: SWIPE_START and SWIPE_DOWN together not firing correctly

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:smileyhappy:. 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.

Please use plain text.
Developer
JRab
Posts: 2,387
Registered: 11-04-2010

Re: SWIPE_START and SWIPE_DOWN together not firing correctly

haha good catch! i totally missed that :smileyvery-happy: good luck!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.