Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
TheDarkIn1978
Posts: 409
Registered: ‎12-10-2010
My Device: PlayBook
My Carrier: N/A

Handling Dragging Off Screen?

suppose you have an object that is draggable.  the typical process:

 

1.  a MouseEvent.MOUSE_DOWN event activates both a MouseEvent.MOUSE_MOVE and MouseEvent.MOUSE_UP.

 

2.  the MouseEvent.MOUSE_MOVE handler activates dragging logic.

 

3.  the MouseEvent.MOUSE_UP handler both deactivates dragging logic and removes the MouseEvent.MOUSE_MOVE and MouseEvent.MOUSE_UP events.

 

how does the PlayBook work with this process if the move leaves the stage / screen onto the bezel?

 

in a typical windowed environment there would be a MouseEvent.MOUSE_OUT event added to the stage, which would simply call the same handler as MouseEvent.MOUSE_UP.  but on the PlayBook (and other AIR compatible mobile devices) does the mouse really leave the stage, or does it remain static bordering the bezel?  


PlayBook Applications:
Drop Swatch
Please use plain text.
Developer
TheDarkIn1978
Posts: 409
Registered: ‎12-10-2010
My Device: PlayBook
My Carrier: N/A

Re: Handling Dragging Off Screen?

[ Edited ]

it seems to work well, according to the simulator (assuming the device functions the same way)

 

 

package
{
	//Imports
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;

	//Class
	public class PlayBookTest extends Sprite
	{	
		//Variables
		private var ball:Sprite = new Sprite();
		
		//Constructor
		public function PlayBookTest()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			stage.frameRate = 60;
			
			stage.addEventListener(MouseEvent.MOUSE_OUT, mouseOutEventHandler);
			
			init();
		}
		
		//Initialize
		private function init():void
		{
			ball.graphics.beginFill(0xFF0000);
			ball.graphics.drawCircle(0, 0, 50);
			ball.graphics.endFill();
			
			ball.x = stage.stageWidth / 2;
			ball.y = stage.stageHeight / 2;
			
			ball.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownEventHandler);
			
			addChild(ball);
		}
		
		//Mouse Down Event Handler
		private function mouseDownEventHandler(evt:MouseEvent):void
		{
			ball.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveEventHandler);
			ball.addEventListener(MouseEvent.MOUSE_UP, mouseUpEventHandler);
		}
		
		//Mouse Move Event Handler
		private function mouseMoveEventHandler(evt:MouseEvent):void
		{
			ball.startDrag();
		}
		
		//Mouse Up Event Handler
		private function mouseUpEventHandler(evt:MouseEvent):void
		{
			ball.stopDrag();
			
			ball.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveEventHandler);
			ball.removeEventListener(MouseEvent.MOUSE_UP, mouseUpEventHandler);
		}
		
		//Mouse Out Event Handler
		private function mouseOutEventHandler(evt:MouseEvent):void
		{
			mouseUpEventHandler(null);
		}
	}
}

 

 


PlayBook Applications:
Drop Swatch
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Handling Dragging Off Screen?

Interesting, but note, I think, that you're getting the MOUSE_OUT not because you've "left the stage" but because the ball is clipped at the edge of the screen and the mouse is leaving the area defined by the clipped ball.

 

When I simply add stage mouse event listeners, I don't see MOUSE_OUT at any time.

 

An unrelated observation, which might be useful to some, is that if you MOUSE_DOWN on the stage, then you continue to get MOUSE_MOVE events even when the mouse is out in the bezel area, with negative coordinates to the left and above, etc.  The MOUSE_UP comes out there as well, if it occurs.

 

If you don't MOUSE_DOWN first, no MOUSE_MOVE events are dispatched while you're out in the bezel area.

 

While I'm on the topic, has anyone else ever noticed that mouse X coordinates go from 0 to 409, then 409.95 and up to 1022.95?  And Y coordinates from 0 to 409, then 409.95 to 598.95?  I have no idea why that would be. I hope it's either completely logical if non-obvious, or simulator-only behaviour.  Might have been throwing someone off if they were expecting something more obvious...

 


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
TheDarkIn1978
Posts: 409
Registered: ‎12-10-2010
My Device: PlayBook
My Carrier: N/A

Re: Handling Dragging Off Screen?

[ Edited ]

 


peter9477 wrote:

Interesting, but note, I think, that you're getting the MOUSE_OUT not because you've "left the stage" but because the ball is clipped at the edge of the screen and the mouse is leaving the area defined by the clipped ball.

 

When I simply add stage mouse event listeners, I don't see MOUSE_OUT at any time.

 

An unrelated observation, which might be useful to some, is that if you MOUSE_DOWN on the stage, then you continue to get MOUSE_MOVE events even when the mouse is out in the bezel area, with negative coordinates to the left and above, etc.  The MOUSE_UP comes out there as well, if it occurs.

 

If you don't MOUSE_DOWN first, no MOUSE_MOVE events are dispatched while you're out in the bezel area.

 

While I'm on the topic, has anyone else ever noticed that mouse X coordinates go from 0 to 409, then 409.95 and up to 1022.95?  And Y coordinates from 0 to 409, then 409.95 to 598.95?  I have no idea why that would be. I hope it's either completely logical if non-obvious, or simulator-only behaviour.  Might have been throwing someone off if they were expecting something more obvious...

 


 

using mouse events on the simulator are not going to be the same on the device, which is why this is a bit difficult to wrap my head around.

 

we can get mouse out events by leaving the stage on the desktop, but the device can only measure the touch position (mouse position) when we're actually touching the screen - it's not going to know that our finger is hovering above the edge of the screen and then into the bezle (eventhough that would be pretty rad if it was able to do that!).  on the device, if the mouse out event works, it will only work if the mouse is down and moving - if the user is touching the screen.

 

i've removed my answer as the solution in the hopes that someone, maybe even someone at RIM, more knowledgable with this issue can address it for us.

 


PlayBook Applications:
Drop Swatch
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Handling Dragging Off Screen?

One thing I think we can say is that MOUSE_OUT events appear to be produced basically as expected provided the button (or finger) is down. 

 

By the way, in case it wasn't clear, I wasn't saying your approach isn't a solution to your problem.  If it did what you needed, I think it's a perfectly reasonable one.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
TheDarkIn1978
Posts: 409
Registered: ‎12-10-2010
My Device: PlayBook
My Carrier: N/A

Re: Handling Dragging Off Screen?

[ Edited ]

 


peter9477 wrote:

 

By the way, in case it wasn't clear, I wasn't saying your approach isn't a solution to your problem.  If it did what you needed, I think it's a perfectly reasonable one.


your post made me realize that it's still unclear.  i don't feel comfortable stating that my above code is a solution without having tested it on the device.  i assume it will work, but i can't be certain right now and it's more likely that a mouse up event would be fired by dragging off the screen and on to the bezle.

 


PlayBook Applications:
Drop Swatch
Please use plain text.