I have created a List with a custom ItemRenderer. The ItemRenderer creates
a label and two Radio Buttons for each item in the list. When one of the
RadioButtons is selected, how would I notify other components that the a
radio button was selected? Would I capture the click event in the
ItemRenderer and then dispatch it to the parent QuestionList Class or is
there another way to do this?
Here is an example of what I am trying to acomplish. Thanks.
Here is my QuestionList Class:
------------------
package
{
import mx.controls.List;
import mx.collections.ArrayCollection;
import mx.core.ClassFactory;
public class QuestionList extends List
{
private var qItems:ArrayCollection;
public function QuestionList()
{
//TODO: implement function
super();
this.qItems = new ArrayCollection();
this.itemRenderer = new ClassFactory(ListItemRenderer);
addQItem("Are you tall?");
addQItem("Are you smart?");
addQItem("Are you quick?");
addQItem("Are you slow?");
this.dataProvider = this.qItems;
}
public function addQItem(s:String):void
{
var o:Object = new Object();
o.label = s;
this.qItems.addItem(o);
}
}
----------------
ListItemRenderer Class:
------------------
package
{
import mx.containers.Canvas;
import mx.controls.RadioButton;
import mx.controls.Label;
import mx.controls.RadioButtonGroup;
public class ListItemRenderer extends Canvas
{
private var lbl:Label;
private var rdoYes:RadioButton;
private var rdoNo:RadioButton;
private var rdoGrp:RadioButtonGroup;
//
public function ListItemRenderer()
{
//TODO: implement function
super();
this.lbl = new Label();
this.rdoNo = new RadioButton();
this.rdoNo.label = "No";
this.rdoNo.setStyle("right",10);
this.rdoYes = new RadioButton();
this.rdoYes.label = "Yes";
this.rdoYes.setStyle("right",60);
this.rdoGrp = new RadioButtonGroup();
this.rdoNo.group = this.rdoGrp;
this.rdoYes.group = this.rdoGrp;
this.addChild(this.lbl);
this.addChild(this.rdoYes);
this.addChild(this.rdoNo);
}
override public function set data(value:Object):void
{
this.lbl.text = value.label;
}
}
}
------------------
--
Troy Simpson