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

One Button Event Limit?

[ Edited ]

two years ago, when i was developing an application for the iPhone, i recall there was a built-in system method that could be called with any touch event that cancelled any other current touch events.  essentially, if you had many buttons on screen, this method insured that the application wouldn't be permitted do crazy things when several button events firing at the same time.

 

problematic:  ButtonA and ButtonB are available.  each button has a mouse up event which fire a specific reorganization/layout of the UI.  if both button's events are fired at the same time, their events will likely conflict, causing a strange new layout, perhaps a runtime error.

 

solution:  application buttons cancel any current pending mouse up events when said button enters mouse down.

 

 

private function mouseDownEventHandler(evt:MouseEvent):void
     {
     //if other buttons are currently in a mouse down state ready to fire
     //a mouse up event, cancel them all here.
     }

 

of course it's simple to manually handle this if there are only a few buttons on stage, but managing buttons becomes more and more complicated / bug-prone if there are several / many buttons available.

 

is there a convenience method available in AIR specifically for this functionality?

 

[EDIT] of interest, i just found some of my old source code for the iPhone.  the method i am referring to is:

 

 

[button setExclusiveTouch:YES];

 

 


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

Re: One Button Event Limit?

[ Edited ]

hey darkin,

 

i think i follow what you are saying somewhat. based on what i got, you can probably use the Event class's stopPropagation or stopImmediatePropagation methods. the stopPropagation method stops any other objects that havent already received the event from receiving it. the stopImmediatePropagation method does the same but takes an extra step and blocks the use of the event even in the current function listener. hope thats what you are looking for. good luck!

 

For more info:

 

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/events/Event.html#stopPropagatio...

 

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/events/Event.html#stopImmediateP...

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: 409
Registered: ‎12-10-2010
My Device: PlayBook
My Carrier: N/A

Re: One Button Event Limit?

[ Edited ]

hi JRab,

 

i'm not sure.  i've used stopPropagation and stopImmediatePropagation to cancel events in an event flow (capturing, target and bubbling phases), but buttons will likely be in different event flows.

 

basically, i have 2 buttons, one in each top corner of the device.  they both have mouse up events that fire different methods.  if i touch down on one without yet lifting my finger, touching down on the other will remove the first button's touch down, as if it was never pressed, even though my finger may still be on the screen.  is that more clear?

 

i guess it would be like stopPropogation but on a global scale.

 

 


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

Re: One Button Event Limit?

[ Edited ]

ah ok i get it now. i was taking into account only one touch point. didnt realize there could be more than one touch down. ill see if i can muster up anything and i find anything ill be sure to report back.

 

Edit: One thing comes to mind. Its not really a built in way but more of a workaround of sorts. We can utilize a singleton class that keeps track of which buttons are pressed down and it'd remove the mouseup listeners on previously pressed button and keep it enabled on the most recent button.

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: 409
Registered: ‎12-10-2010
My Device: PlayBook
My Carrier: N/A

Re: One Button Event Limit?

[ Edited ]

yeah yeah... and maybe each registered button would listen for a custom event which kills it's mouse events when any other button is pressed / dispaches the custom kill event.  i assume that could be how the singleton class could work?


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

Re: One Button Event Limit?

hey,

 

yeah you have the right idea. all buttons taht you want to keep track of would have the mouseDown event listener pointing to the same function. within that function you would check the singleton class if there are any previous buttons already registerd for the mouseup event. if there are remove those and then add the mouse up listener to the new button and add that to the singleton object.

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