Solved

Dynamic creation of radio buttons in a radio group, using a custom object?

Posted on 2009-04-09
2
823 Views
Last Modified: 2012-05-06
All,

I'm looking for information on how to create a radio button group, based on the contents of an list of objects.
These objects, of type "Answer" have 2 string properties of "answerLetter" and "answerValue".

What I want to do is iterate over this collection of Answer objects, and create a radio button group, with the label being the Answer Value and the data being the Answer Letter.

How would I do this?  It appears to be adding the contents of my array collection as new radio buttons, but they are all on top of each other.  How do I space them out?  The text values appear to be populating correctly, but there appears to be n number of buttons on top of each other...
Simple answer class...
 

public class Answer

{

	private var _answerText:String;

	private var _answerLetter:String;

		

	public function Answer(...args)

    	{

  		this._answerLetter = args[0];

    		this._answerText = args[1];     		

    	}

		

        public function get answerText():String{

            return _answerText;

        }

        

        public function set answerText(answerText:String):void{

            _answerText = answerText;

        }

        

        public function get answerLetter():String{

            return _answerLetter;

        }

        

        public function set answerLetter(answerLetter:String):void{

            _answerLetter = answerLetter;

        }     

}
 

The panel has this on it.
 

<mx:RadioButtonGroup id="answerGroup" />

        <mx:Repeater id="rep" dataProvider="{cbCol}">

                <mx:RadioButton group="{answerGroup}" id="radios" label="{rep.currentItem.answerText}" data="{rep.currentItem.answerLetter}" />

        </mx:Repeater>
 

cbCol is populate when this method is called.

public function CreateRadioButtons(answersForThisQuestion:ArrayCollection){

				

	cbCol = new ArrayCollection();

	for(var i:int = 0; i<answersForThisQuestion.length; i++){		  cbCol.addItem(answersForThisQuestion.getItemAt(i) as Answer);

	}

			

}

Open in new window

0
Comment
Question by:csciguy81
2 Comments
 
LVL 5

Accepted Solution

by:
Fuzzy_Logic_ earned 50 total points
ID: 24110470
Put the RadioButtonGroup in a Tile component.
<mx:Tile direction="horizontal">
 

<mx:RadioButtonGroup id="answerGroup" />

        <mx:Repeater id="rep" dataProvider="{answersForThisQuestion}">

                <mx:RadioButton group="{answerGroup}" id="radios" label="{rep.currentItem.answerText}" data="{rep.currentItem.answerLetter}" />

        </mx:Repeater>

 

    

</mx:Tile> 

Open in new window

0
 

Author Closing Comment

by:csciguy81
ID: 31568662
Worked great!  Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
countClumps  challenge 10 113
Microsoft Edge 9 93
count8 challlenge 13 118
Having trouble setting Apache to recognise 2 vitual sites (on different drive). 3 60
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now