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
Posts: 29
Registered: ‎11-14-2010
My Device: Playbook

Re: Sprite not cooperating with MouseEvent.DOUBLE_CLICK?

Hi zezke,

 

I just tried your last sample code in simulator with test.doubleClickEnabled set to true and double click event is working. My OS is Win XP and I'm using VMware Player.

 

What is your OS and virtual machine?

Developer
Posts: 409
Registered: ‎12-10-2010
My Device: PlayBook

Re: Sprite not cooperating with MouseEvent.DOUBLE_CLICK?

[ Edited ]

doubleClickEnabled works perfectly fine with AIR for desktop.

 

it's not entirely necessary to call super when extending a sprite.

 

simple example:

 

 

package
{
import flash.display.Sprite;
import flash.events.MouseEvent;

public class Test extends Sprite
    	{
    	public function Test()
        	{
		init();
		}
		
	private function init():void
		{
		var myRect:MyRectangle = new MyRectangle(100, 200, 0xFF00FF);
		myRect.x = myRect.y = 100;
		myRect.doubleClickEnabled = true;
		myRect.addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickEventHandler);
		
		addChild(myRect);
		}
		
	private function doubleClickEventHandler(evt:MouseEvent):void
		{
		trace("doubleClicked");
		}
    	}
}

 

 

package
{
import flash.display.Sprite;

public class MyRectangle extends Sprite
	{
	public function MyRectangle(width:Number, height:Number, color:Number)
		{
		graphics.beginFill(color);
		graphics.drawRect(0, 0, width, height);
		graphics.endFill();
		}
	}
}

 

 

 

 


PlayBook Applications:
Drop Swatch
Developer
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: Sprite not cooperating with MouseEvent.DOUBLE_CLICK?

Oops, my bad, looks like I used doubleClickEnabled wrong. I used it in the first Sprite and assumed that it was enabled for all children. Thank you guys!

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: Sprite not cooperating with MouseEvent.DOUBLE_CLICK?

I conducted a new test, I was experiencing some double clicks problems (again), this time in combination with the Label class. Here is my test code:

 

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	
	import qnx.ui.text.Label;
	
	public class DoubleClickLabelTester extends Sprite
	{
		public function DoubleClickLabelTester()
		{
			var testLabel:Label = new Label();
			testLabel.text = "DOUBLE CLICK ME!";
			testLabel.x = (stage.stageWidth - testLabel.width)/2;
			testLabel.y = (stage.stageHeight - testLabel.height)/2;
			addChild(testLabel);
			testLabel.doubleClickEnabled = true;
			testLabel.addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClick);
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
		}
		
		public function onDoubleClick(event:MouseEvent):void{
			trace("Double click registered!");
		}
	}
}

 

Doesn't work unfortunately.

 

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Posts: 409
Registered: ‎12-10-2010
My Device: PlayBook

Re: Sprite not cooperating with MouseEvent.DOUBLE_CLICK?

[ Edited ]

strange.  i tried adding a double click to the QNX Label instance and i also couldn't get it to work, but adding a single click mouse event to the QNX Label worked fine.

 

however, what does work and what makes more sense is to assign and capture input of any mouse/touch events to the label's read-only textField property rather than the label itself.

 

working example:

 

 

package
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import qnx.ui.text.Label;
	
	public class PlayBookTest extends Sprite
	{
		public function PlayBookTest()
		{
			var label:Label = new Label();
			label.text = "Double Click Test";
			label.x = label.y = 100;
			label.textField.doubleClickEnabled = true;
			label.textField.addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickEventHandler);
			
			addChild(label);
		}
		
		private function doubleClickEventHandler(evt:MouseEvent):void
		{
			trace("Double Clicked");
		}
	}
}

 

 


PlayBook Applications:
Drop Swatch
Developer
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: Sprite not cooperating with MouseEvent.DOUBLE_CLICK?

Thank you, I had no idea this was possible.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Sprite not cooperating with MouseEvent.DOUBLE_CLICK?

 


TheDarkIn1978 wrote: 

however, what does work and what makes more sense is to assign and capture input of any mouse/touch events to the label's read-only textField property rather than the label itself.


 

Would that prevent it from registering clicks that are just outside the bounds of the label but still inside the borders of the button?

 

Also, if this is to be used on a multitouch device, it could make the clickable/touchable region much too small.  I seem to recall reading that the QNX controls have extended hitTest regions to allow for easier tagetting with the finger.  That might not work if you do what's described here.

 

(These are just speculations...)


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!
Developer
Posts: 409
Registered: ‎12-10-2010
My Device: PlayBook

Re: Sprite not cooperating with MouseEvent.DOUBLE_CLICK?

[ Edited ]

you're right, i never though of that.  i suppose it would be best to assign the listener to the label rather than the label's textField property, especially if the font is quite large, but that currently doesn't seem to work for double click - unless it's a bug in the simulator only.

 

for small/regular sized font on touch based devices the difference is probably negligible, assuming the label's read-only textField property isn't set larger than normal via override.


PlayBook Applications:
Drop Swatch