4 Replies Latest reply on Feb 14, 2009 4:35 AM by byuhobbes85

    Update itemRenderer at Runtime


      Above is a link to a screenshot of a simple test authoring tool I am creating with Flex. On the left is an editable List control that contains possible responses. On the right is another editable List control that contains test questions. Each test question has a TextInput control to specify the question prompt, and then a ComboBox to specify which of the responses on the left is the correct response for that question.

      It took a bit of work to update the itemRenderer on the right when a change was made on the left, but that is working fine now. However, when I add a new question to the List on the right, the ComboBoxes render the first item in their dataProvider, whether or not that item was selected before the new question was added.

      I have attached my code. You should be able to just copy, paste, and run. Add a few questions, play with the values in both lists, and then add another question. You will see the weirdness with the ComboBoxes. You can click the "Check Data" button at any time to see the text of each input and selected index of each ComboBox.

      Can anyone help me here?


        • 1. Re: Update itemRenderer at Runtime
          Gregory Lafrance Level 6
          Refresh responseData at the end of the addQuestion method:
          • 2. Re: Update itemRenderer at Runtime
            ntsiii Level 3
            The refresh() method is intended to be used with filters or sorts and causes the sort or filter to be re-applied to the collection.

            If that works here, it is a side effect.

            Using AddItem *should* be all that is necessary. I don't use inline renderers and binding because they are hard to debug.
            • 3. Re: Update itemRenderer at Runtime
              rtalton Level 4
              Hey, byuhobbes85
              If you add one more thing to your item render:
              <mx:Text text="{data.selectedResponse}"/>
              ..you'll see some interesting behavior when you:
              1) change a value in the first combobox to "b", and then add a new item to the List.
              2) change that same combobox back to "a", then add another new item to the List.
              Note the value shown in the new text box. Weird stuff, but it does look like an issue with either the dataprovider not updating, or the combo box not updating.
              • 4. Re: Update itemRenderer at Runtime
                byuhobbes85 Level 1
                Thank you Greg, the .refresh() function solved all of the rendering issues. I had had similar rendering issues with dynamically modified tree controls, and I remembered that the .validateNow() function had to be used to re-render the control after any changes. I had tried that with this list control, but to now avail. I'll have to look at the differences between these two functions, what they're used for, and what problems they are intended to solve.

                Thanks everyone!