1 Reply Latest reply on Apr 1, 2012 11:22 AM by Shongrunden

    Calling ensureIndexIsVisible after adding items to the dataProvider

    Roy Nevo Level 1

      Hi,

       

      I get a strange behavior where calling ensureIndexIsVisible doesn't show the correct item.

      Am I missing the correct event to listen to after adding items to list data provider?

       

      Description:

      I use spark.components.List with an HorizontalLayout to display my data.

      My data is displayed using ItemRenderer's.

       

      After adding new items to the dataProvider I register to Event.RENDER and within this handler I call ensureIndexIsVisible and unregister to this event.

       

      // adding some data to dataProvider - a few thousnd items

      list.dataProvider.add(...)

       

      list.addEventListener(Event.RENDER,

                                                                  function renderHandler(e:Event):void

                                                                  {

              // show index

              list.ensureIndexIsVisible(indexToShow);

              list.removeEventListener(Event.RENDER, renderHandler);

        });

       

      Debugging I've done:

      1. If I comment out removeEventListener, it will eventually work after a few times the event fires.

      2. The initial location that I see is a few items behind so if i scroll a little I can find the desired item

       

      Thanks,

      Roy.