4 Replies Latest reply on Oct 19, 2010 6:51 AM by John Hall

    Spark methods to refresh itemrenderer

    John Hall Level 4

      I'm porting an app to spark components and a list I have has it's arrayCollection update and the item appears in the list but is transparent until I leave the screen and come back forcing the spark component itemRenderer to refresh. I've not hit on the solution for which I used to use invalidateList in Flex 3. Any suggestions? Things I've tried:

       

      refresh the dataProvider

      set the itemRenderer to null then set it back to the actual itemRenderer with pickBox.itemRenderer = new ClassFactory(renderers.Renderer_People)

      setting the dataProvider to null then reassigning it

      listbox.invalidateProperties()

      listbox.validateNow()

      listbox.invalidateDisplayList

       

      etc.

       

      Again, the object is there but the type cannot be seen (simple itemRenderer - a label with black type). All surrounding items are rendered but not the new item. It just looks like white on white (though I can use the data if I drag and drop it to another list box).

       

      Suggestions?

       

      UPDATE: I just realized it's always the last item in the list, not the last data object added to the list, if that rings any bells.

        • 1. Re: Spark methods to refresh itemrenderer
          Flex harUI Adobe Employee

          Space for it is allocated but nothing is drawn?  If you click on that space

          does it select and show selection?  What if you use default renderer?

          1 person found this helpful
          • 2. Re: Spark methods to refresh itemrenderer
            John Hall Level 4

            Regarding selection, yes it shows that there's data there. I could be convinced it's white font on whate background. If I drag the highlighted blue rectangle to a dropTarget, the actual data shows up.

             

            Re: default renderer. Good point. Yes, the type shows fine with the default itemRenderer. Which begs the question re: what did I do wrong with

            the itemRenderer. It'll probably pop out for you, but not me:

             

            <?xml version="1.0" encoding="utf-8"?>
            <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                            xmlns:s="library://ns.adobe.com/flex/spark"
                            xmlns:mx="library://ns.adobe.com/flex/mx"
                            autoDrawBackground="true">

             

                <fx:Script>
                    <![CDATA[
                        import com.cactusware.managers.TeamPM;
                       
                        import mx.collections.ArrayCollection;
                        public var teamPM : TeamPM; // Presentation manager using Mate

             

                        [Bindable]
                        private var isIncluded : Boolean = false;

             

                        private function getDisplayName( item : Object ) : String {
                            isIncluded = false;
                            var coaches:ArrayCollection = teamPM.currentTeam.coaches;
                            if ( coaches != null && coaches.length > 0 ) {
                                for ( var i : uint = 0; i < coaches.length; i++ ) {
                                    if ( item.GUID == coaches.getItemAt( i ).GUID ) {
                                        isIncluded = true;
                                        break;
                                    }
                                }
                            }
                            return item.lastName + ", " + item.firstName;
                        }
                    ]]>
                </fx:Script>

             

                <mx:Spacer width="1"/>
                <mx:Image y="0"
                          source="assets/images/icons16/check.png"
                          visible="{isIncluded}"
                          left="1"/>
                <s:Label text="{getDisplayName(data)}"
                         paddingTop="5"
                         paddingBottom="5"
                         paddingLeft="4"
                         fontSize="13"
                         width="128"
                         color="#000000"
                         left="14"/>
            </s:ItemRenderer>

            • 3. Re: Spark methods to refresh itemrenderer
              John Hall Level 4

              The other clue is that if I doubleClick on the list or drag and drop anything from the list or change states of the component in which the list is in, it re-renders correctly. So some 'normal' even causes it to re-render properly but I have yet to hit upon it. Using a dataRenderer works, but I give up some  of the flexibility of the various states.

              • 4. Re: Spark methods to refresh itemrenderer
                John Hall Level 4

                OK, never mind. Let's just say I like the new itemRendererFunction. Much simpler and it works. Yea.