Thanks Michael.
On 9/11/07, Michael Schmalle <[EMAIL PROTECTED]> wrote:
>
> Troy,
>
> I meant to quote this...
>
> > have the event bubble from the itemRenderer, and that is about it. And
> listen for it
>
> Don't do that, your idea is right.
>
> Peace, Mike
>
> On 9/11/07, Michael Schmalle <[EMAIL PROTECTED]> wrote:
> >
> > > I was thinking that I could listen for the click event on the radio
> > buttons,
> > capture the event, and dispatch a new custom event.
> >
> > Troy,
> >
> > Do this. I don't recommend bubbling events especially in itemRenderers.
> > You are just asking for trouble down the road.
> >
> > Unless your event is called AASDSD_32213_EVENT. :)
> >
> > Bubbling events can cause naming collisions.
> >
> > I would just handle the event in the itemRenderer and dispatch and event
> > through the listOwner.
> >
> > Then you can just add a listener to the List instance.
> >
> > Peace, Mike
> >
> >
> > This code should work, I didn't test it. ;-)
> >
> >
> > //--------------------------------------------------------------------------------------------------------------
> >
> >
> > package my.renderers
> > {
> >
> > import mx.containers.Canvas;
> > import mx.controls.Label;
> > import mx.controls.RadioButton;
> > import mx.controls.RadioButtonGroup;
> > import mx.controls.listClasses.IDropInListItemRenderer ;
> > import mx.controls.listClasses.ListData;
> > import mx.events.ItemClickEvent;
> >
> > public class ListItemRenderer
> > extends Canvas
> > implements IDropInListItemRenderer
> > {
> >
> > private var lbl:Label;
> > private var rdoYes:RadioButton;
> > private var rdoNo:RadioButton;
> > private var rdoGrp:RadioButtonGroup;
> >
> > //----------------------------------
> > // listData
> > //----------------------------------
> >
> > private var _listData:ListData;
> >
> > [Bindable("dataChange")]
> >
> > public function get listData():BaseListData
> > {
> > return _listData;
> > }
> >
> > public function set listData(value:BaseListData):void
> > {
> > _listData = ListData(value);
> > invalidateProperties();
> > }
> >
> > //----------------------------------
> > // data
> > //----------------------------------
> >
> > protected var dataChanged:Boolean = false;
> >
> > override public function set data(value:Object):void
> > {
> > super.data = value;
> > dataChanged = true;
> > invalidateProperties();
> > }
> >
> >
> > public function ListItemRenderer()
> > {
> > super();
> > }
> >
> >
> > override protected function createChildren():void
> > {
> > super.createChildren();
> >
> > lbl = new Label();
> >
> > rdoNo = new RadioButton();
> > rdoNo.label = "No";
> > rdoNo.setStyle("right",10);
> >
> > rdoYes = new RadioButton();
> > rdoYes.label = "Yes";
> > rdoYes.setStyle("right",60);
> >
> > rdoGrp = new RadioButtonGroup();
> >
> > rdoGrp.addEventListener(
> > ItemClickEvent.ITEM_CLICK,
> > itemClickHandler);
> >
> > rdoNo.group = rdoGrp;
> > rdoYes.group = rdoGrp;
> >
> > addChild(lbl);
> > addChild(rdoYes);
> > addChild(rdoNo);
> >
> > }
> >
> > override protected function commitProperties():void
> > {
> > super.commitProperties();
> >
> > if (dataChanged)
> > {
> > if (data)
> > {
> > lbl.text = data.label;
> > }
> > dataChanged = false;
> > }
> > }
> >
> > private function itemClickHandler(event:ItemClickEvent):void
> > {
> > if (_listData)
> > {
> > var e:RadioButtonEvent =
> > new RadioButtonEvent(
> > RadioButtonEvent.RADIO_CLICK, event);
> > _listData.owner.dispatchEvent(e);
> > }
> > }
> > }
> > }
> >
> > //--------------------------------------
> > // Custom Event
> > //--------------------------------------
> > package my.events
> > {
> >
> > import mx.events.ItemClickEvent;
> > import flash.events.Event;
> >
> > public class RadioButtonEvent extends Event
> > {
> > public var itemClickEvent:ItemClickEvent;
> >
> > public function RadioButtonEvent(type:String,
> > itemClickEvent:ItemClickEvent)
> > {
> > super(type, false, false);
> > this.itemClickEvent = itemClickEvent;
> > }
> > }
> > }
> >
> > //--------------------------------------------------------------------------------------------------------------
> >
> >
> >
> > On 9/11/07, Troy Simpson < [EMAIL PROTECTED]> wrote:
> > >
> > >
> > > Would you have an example of how to do this with the example code that
> > > I provided?
> > >
> > > I was thinking that I could listen for the click event on the radio
> > > buttons, capture the event, and dispatch a new custom event.
> > >
> > > Thanks,
> > >
> > >
> > > On 9/11/07, Sheriff <[EMAIL PROTECTED]> wrote:
> > > >
> > > > have the event bubble from the itemRenderer, and that is about
> > > > it. And listen for it
> > > >
> > > > ----- Original Message ----
> > > > From: Troy Simpson < [EMAIL PROTECTED] >
> > > > To: [email protected]
> > > > Sent: Tuesday, September 11, 2007 3:40:27 PM
> > > > Subject: [flexcoders] How to dispatch event from ItemRenderer?
> > > >
> > > >
> > > > 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.ClassFactor y;
> > > >
> > > >
> > > > public class QuestionList extends List
> > > > {
> > > > private var qItems:ArrayCollect ion;
> > > > 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:RadioButtonG roup;
> > > > //
> > > > 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
> > > >
> > > >
> > > > ------------------------------
> > > > Shape Yahoo! in your own image. Join our Network Research Panel
> > > > today!
> > > > <http://us.rd.yahoo.com/evt=48517/*http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7>
> > > >
> > > >
> > >
> > >
> > > --
> > > Troy Simpson
> > >
> > >
> >
> >
> > --
> > Teoti Graphix
> > http://www.teotigraphix.com
> >
> > Blog - Flex2Components
> > http://www.flex2components.com
> >
> > You can find more by solving the problem then by 'asking the question'.
>
>
>
>
> --
> Teoti Graphix
> http://www.teotigraphix.com
>
> Blog - Flex2Components
> http://www.flex2components.com
>
> You can find more by solving the problem then by 'asking the question'.
>
>
>
--
Troy Simpson