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
Highlighted
Contributor
Posts: 16
Registered: ‎01-04-2011
My Device: Not Specified
My Carrier: Java Developer

Button with event listener inside a scrollPane

Hi all

I have make a scrollPane with inside images and buttons(the buttons are over the images).The button have a mouseClick event but it seems tha on click it catches only the events of scrolling o mouse click of the scroll Pane and not the events Inside the scrollContent.Is there any way to make it possible?

Developer
Posts: 153
Registered: ‎10-26-2010
My Device: Bold 9900
My Carrier: AT&T

Re: Button with event listener inside a scrollPane

Hi,

 

This is a bunch of code fragments of how I implement my wallpaper browser:

 

 

		private var moreButtons:Array;					// picture buttons
		private var back_screens:uint;					// number of pictures
		private var pcn:uint;						// current picture being loaded
		private var fileGridScroll:ScrollPane;				// scroll pane so more than 18 can be shown
		private var fileGrid:Sprite;					// put buttons on this, then this on scrollpane
...
			fileGridScroll = new ScrollPane();
			fileGridScroll.scrollDirection = "vertical";
			fileGrid = new Sprite();
			moreButtons = new Array();
...
			for (i=0;i<back_screens;i++) {				// create buttons
				moreButtons[i] = new IconButton();
				if (br_x == 6) {
					br_x = 0;
					br_y ++;
				}
				xln = br_x * 166 + 4;
				yln = br_y * 120;
				moreButtons[i].setPosition(xln, yln);
				moreButtons[i].setSize(152, 92);
				//b.setIcon();
				moreButtons[i].name = finalList[i].url;
				fileGrid.addChild(moreButtons[i]);
				moreButtons[i].addEventListener(MouseEvent.CLICK, getBrowse);
				br_x ++;
			}
...
			fileGridScroll.setSize(1000,424);		// leave room for scrollbar
			fileGridScroll.setPosition(16,110);
			fileGridScroll.setScrollContent(fileGrid);
			fileGridScroll.update();
			removeChild(activityIndicator);
			addChild(fileGridScroll);

 

Therefore:  Each button is part of an array and is added to a common listener which determines what button is pressed by its .name.  The buttons are added to a sprite and the sprite is added to the scrollpane.

 

Harry

--------------
Accepted PlayBook Applications: Marmi-doos, BASIC, Run and Hide, SuperClip
Accepted OS4-7 SmartPhone App: KeepLightOn
Developer
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: Button with event listener inside a scrollPane

What happens if a user presses a button, drags the pane, and lets go. Aren't your mouse handlers going to register that as a click? 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Button with event listener inside a scrollPane

If the mouse up occurs while still inside the button, it should fire off a click event.

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Button with event listener inside a scrollPane

hey shawn,

 

i think the scrollpane is designed to cancel the mouse slick event whenever a user scrolls. you can see it in action in the list class of the QNX api's. but yah normally even if you were to drag your mouse up and down as soon as you let go a click would go off.

 

that being said i gotta say the scrollpane class is probably my favorite class out of all of the API's. *knocks on wood that nothing changes*

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
Developer
Posts: 153
Registered: ‎10-26-2010
My Device: Bold 9900
My Carrier: AT&T

Re: Button with event listener inside a scrollPane

Hi,

 

I haven't gotten any spurious clicks while dragging on the simulator.  It works the way I want it to - drag does drag & click does click.

 

Harry

--------------
Accepted PlayBook Applications: Marmi-doos, BASIC, Run and Hide, SuperClip
Accepted OS4-7 SmartPhone App: KeepLightOn
Developer
Posts: 165
Registered: ‎10-26-2010
My Device: BlackBerry® PlayBook™
My Carrier: .

Re: Button with event listener inside a scrollPane

[ Edited ]

 

button.addEventListener(MouseEvent.MOUSE_DOWN, cancelBubble);

private function cancelBubble(e:Event):void
{
    e.stopPropagation();
}

 

Both List and ScrollPane handle events in ways that may not be expected. The above should stop the ScrollPane from scrolling or receiving the MOUSE_DOWN event when the button is clicked. it's also useful in other situations with List and ScrollPane for items that float above them in z-order or to stop select/deselect in Lists.

 

Whether you use this or not, though, your button should still receive the CLICK event on MOUSE_UP like John posted.

 

Developer
Posts: 153
Registered: ‎10-26-2010
My Device: Bold 9900
My Carrier: AT&T

Re: Button with event listener inside a scrollPane

Hi,

 

Note that the browser responds the same way.  If you do a scroll up or down starting at a link, it scrolls and doesn't trigger the link. Could be it's coded with a scrollpane?

 

Harry

--------------
Accepted PlayBook Applications: Marmi-doos, BASIC, Run and Hide, SuperClip
Accepted OS4-7 SmartPhone App: KeepLightOn