7 Replies Latest reply on May 1, 2009 3:10 PM by ntsiii

    Changing values in custom item renderer


      I have an xml feed that I am using to populate a List control. The list control has it's itemRenderer property set to CustomListItem which a custom component built by me to display various pieces of data from the xml along with an icon. At certain points I would like to ba able to tell one of the fields in CustomListItem to change from displaying xml.firstData to xml.secondData depending on a radio button selection but I can't find a way to access the properties of CustomListItem from main.mxml (which is where the radio buttons are).

      At the moment the values in CustomListItem are set using functions within it to parse the 'data' property.


      Sorry if this is a bit of a sketchy explanation of my problem Any suggestions would be great.



        • 1. Re: Changing values in custom item renderer
          Michael Borbor Level 4

          Use outerDocument.myCheckBox to verify the status of the checkboxes within

          your item renderer

          • 2. Re: Changing values in custom item renderer
            ATIF FAROOQ Level 3


               do you want to change the properties in all of the itemRenderes in the list or only Particular itemRenderers like in selectedItem etc ?

            • 3. Re: Changing values in custom item renderer
              Gregory Lafrance Level 6

              I hope this code represents your situation, but at least I hope it helps you!


              ----------------------- main app ----------------------------

              <?xml version="1.0"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%"
                height="100%" creationComplete="dataRequest.send();"
                xmlns:comp="*" horizontalAlign="left">
                    import mx.rpc.events.ResultEvent;
                    import MyListItems;
                    import mx.collections.XMLListCollection;
                    [Bindable] private var xmllist:XMLList;
                    [Bindable] private var xlc:XMLListCollection;
                    private function resultHandler(evt:ResultEvent):void{
                      xmllist = evt.result.item;
                      xlc = new XMLListCollection(xmllist.firstData);
                    private function changeData(evt:Event):void{
                      if(evt.currentTarget.label == "First Data"){
                        xlc = new XMLListCollection(xmllist..firstData);         
                        xlc = new XMLListCollection(xmllist.secondData);         
                <mx:HTTPService id="dataRequest" useProxy="false" url="data.xml"
                  resultFormat="e4x" result="resultHandler(event)"/>
                <mx:RadioButtonGroup id="items"/>
                <mx:RadioButton group="{items}" label="First Data" change="changeData(event)"
                <mx:RadioButton group="{items}" label="Second Data" change="changeData(event)"/>
                <mx:List width="100" height="150" itemRenderer="MyListItems"
              ----------------------- item renderer --------------------------

              <?xml version="1.0" encoding="utf-8"?>
              <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">
                <mx:Text text="{data}"/>
              ------------------------------- data.xml ---------------------------

              <?xml version="1.0" encoding="utf-8"?>

              • 4. Re: Changing values in custom item renderer
                invisibleBlade Level 1

                I need to change the value in all the items.

                The app I am building is basically a list of contact data for people within my company. By default the list displays a flag icon depending on the persons country and there name. There is a final field that displays contact details and this is the one I want to switch between to display either email, mobile, or phone number. The user clicks a radio button in main.mxml to select one of these and from then on the list displays the data they have chosen.


                Hope this is a bit clearer


                • 5. Re: Changing values in custom item renderer
                  invisibleBlade Level 1

                  That is helpful and definately gives me something to work with. The only trouble is that in my CustomListItem the 'data' property is complex xml node with many child nodes nested within. A function in CustomListItem parses the data and populates the text fields.


                  Is there a way that I can define a changeData method in my CustomListItem and then call it from main.mxml or do I have to make changes to the data provider as in the example in the post above?

                  • 6. Re: Changing values in custom item renderer
                    Gregory Lafrance Level 6

                    I think the easiest way to accomplish what you are saying is to have a field in your data that specifies whether firstData or secondData should be displayed. Then in your radio button change handler, simply change the data in the dataprovider for the list.

                    • 7. Re: Changing values in custom item renderer
                      ntsiii Level 3

                      Hold on now, if this is true:

                      "I need to change the value in all the items."


                      And the state of this part of the renderer is NOT dependent on the row data, then a [Bindable] variable in the main app and a changeWatcher in the renderer should do it.