If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
Kai001
Posts: 200
Registered: ‎03-10-2011
My Device: Not Specified
Accepted Solution

Unnecessary RadioButtonGroup code?

[ Edited ]

I've made a radio buttons, and then a radio button group. I made the group part like this:

 

var MyRBG:RadioButtonGroup = RadioButtonGroup.getGroup('MyGroup');
MyRBG.addEventListener(Event.CHANGE, ToggleTimeFormat);

 

But in the example code there's a lot of  "extra" code. It looks like this:

 

var rbg1:RadioButtonGroup;
rbg1 = RadioButtonGroup.getGroup("rbg1_meals13");
rbg1.addButton(rb1);
rbg1.addButton(rb2);
rbg1.addButton(rb3);
rbg1.addEventListener(MouseEvent.CLICK, rbg1Change);
 rbg1.setSelectedRadioButton(rb2);

 

Why do I need to run the addButton function and setSelectedRadioButton? It seems extremely redundant. Am I missing something here? It seems to work without them for me. Although I just had to change "MouseEvent.CLICK" to "Event.CHANGE".

 

SIDE QUESTION:

Is there any advantage to using the QNX label over the Flash TextField?

 

SIDE-SIDE QUESTION:

Is there an award for asking a lot of questions? Anyway, do event listeners need to be removed manually even if the place they were created from no longer exists? I mean, if I have a MovieClip that adds an "OnEnterFrame" event listener. And then I remove the MovieClip, will the event listener stop running? The answer so far seems to be that I need to manually remove it. But I'd like to get an answer from someone who knows.

 

SIDE-SIDE-SIDE QUESTION:

When the radio button group change event runs, is there any way to find out what option was selected without having to manually check each button? EDIT: I found a way to find what button was clicked, but how can I identify what button is what when they don't have names? Compare labels? Is that really the only/best way?

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Unnecessary RadioButtonGroup code?

hey Kai,

 

In regards to the additional code in the example, the API is in beta so there is a lot of redundant code. Also I guess they like giving you more options. So sometimes dont need all of it for your program to work. so its a hit or miss kind of deal and its up to you to decide what you need.

 

In regards to Label class vs the TextField class, we have been told that the QNX components are optimized for the touch screen. so that leaves us to assume they recommend us use the QNX components wherever possible for compatibility. again this is up to you.

 

In regards to the removal of listeners, it is HIGHLY recommended that you manually remove the event listeners when they are not in use. If you dont, then the garbage collector (whenever its run randomly in the background) will NOT remove the object from memory since it still has a "connection" to the application. So in the short run it wont change anyhting but in the long run you may run into memory related problems. so definitely remove them manually.

 

In regards to the lack of knowing which radio button was clicked i COMPLETELY agree this is an oversight on the API's part. i was in the same poistion. you'd think there'd be some kind of index to tell the buttons apart right? wrong. there is just hte button instance with no useful values. so what i did in my apps is i extended the RadioButton class and added a new index property to the class. that way i can set it in my application and tell it apart from the other buttons. here is my custom radiobutton class:

 

CustomRadioButton.as:

 

 

package
{
	import qnx.ui.buttons.RadioButton;
	
	public class CustomRadioButton extends RadioButton
	{
		private var _index:int = -1;
		
		public function CustomRadioButton()
		{
			super();
		}
		
		public function set index(value:int):void
		{
			_index = value;
		}
		
		public function get index():int
		{
			return _index;
		}
	}
}

 

so in my main application i would set the radio button's index manually so i know what is clicked. hope that clears up your problems. 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.
Developer
Kai001
Posts: 200
Registered: ‎03-10-2011
My Device: Not Specified

Re: Unnecessary RadioButtonGroup code?

[ Edited ]

Wow! Thanks so much! You managed to answer all the questions. I didn't expect anyone to answer them all in one post.

 

I'll just skip the parts that I think are redundant.

 

As for the textfields I think I'll swap them with labels.

 

Also, about the radiobuttons, I was able to get them working without any identifier. I have 2 radiobuttons that I'm using two allow the user to switch on option from being enabled to disabled. If the saved value is "true" then I know that the enabled switch should be selected. And if the other button gets clicked I just invert the saved value (!MyValue). Although this really only works for this, if I do anything more complex with radio buttons I'll probably do something like what you posted. Thanks!

 

And finally, about the listeners, as you said, I'll manually remove them. But I'm not sure wether this will solve my problem, because I've set ALL event listeners in my app to be weak. I also made sure to delete any references to it and remove it from the stage. Yet for some bizzare reason it still runs. So although manually removing them will stop them from running I have a feeling that the MovieClip will still be loaded in memory. I've even confirmed that it no longer has a parent (It says null for parent).

Please use plain text.
Developer
Kai001
Posts: 200
Registered: ‎03-10-2011
My Device: Not Specified

Re: Unnecessary RadioButtonGroup code?

[ Edited ]

Sorry for the double post. I have another problem.

 

I have a series of horizontal containers like this:

___________________

|Label: [Button] [Button] |

|Label2: [Drop Down]    |

|Label3:                            |

|List box                            |

|                                          | 

 

The problem is that  the drop down list, when expanded appears behind the listbox below it. I've looked up Z-ordering in AS3 and I'm not sure what to do.

 

I thought I could just change the Z-orders of the containers, but when I use "setChildIndex" to change the depth it actually changes the items place in the list. For example "setChildIndex(Container2, 0);" moves the second container to the beggining of the list..

 

SIDE-QUESTION: Can I have my lots'o'questions award now? Anyway, is ther a numeric stepper in the QNX components? You know a textbox that contains a number with buttons to increment it up and down. I guess I could make my own but it would be nice if there was one built in

I guess I won't need a numeric stepper. I found the "picker" that should do what I want. But I want the user to be able to pick a date. How can I do this while taking leap year and shorter-than-31-day-month logic? Do I really have to write a complex script for that?

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Unnecessary RadioButtonGroup code?

In the community library, there is a date chooser so you dont have to worry about <31 months.  It is like the Flex Date Chooser with a calendar chooser popup.

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Unnecessary RadioButtonGroup code?

hey kai,

 

you had the correct approach for the "Z-order" problem. just one thing you need to do is place that setChildIndex() code at the end of your code. that means, AFTER any .layout() or .setSize() calls are made on any containers in your application. Whats happening is the containers use the order of their children to determine what goes where. so when you change the order by calling the setChildIndex() method, you are telling hte container to change the order as well. and when the setSize or layout methdos are called, it uses the new indexes to reposition the children in side of the container.

 

so to summarize, call the setChildIndex after any layout or setSize methods are called in your app. and rememebr to "reset" the indexes when you need to call the setSize or layout methods later. here is a post from the past of someone asking the same thing:

 

http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/Few-Issues-with-application-simul...

 

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.
Developer
Kai001
Posts: 200
Registered: ‎03-10-2011
My Device: Not Specified

Re: Unnecessary RadioButtonGroup code?

[ Edited ]

jtegen: Thanks for the reply! I think you could have just saved me a LOT of time! I'm having some problems with the library and I've posted in the thread about them. EDIT: Nevermind EDIT: Nevermind about the nevermind, just hit a problem.

 

JRab: It works perfectly! I did look to see if anyone else asked the same question already, but I didn't find anything that worked.

 

Thanks everyone!

Please use plain text.