4 Replies Latest reply on Feb 28, 2008 7:50 PM by peterent

    Reference an item in a TileList

    injpix Level 3
      When a TileList component utilizes its itemRenderer property, i.e.;
      // myItemRenderer.mxml – is a VBox component
      tileListInstance.itemRenderer = new ClassFactory(myItemRenderer);

      …how can one reference an item (in the tileListInstance component) via ActionScript?

      Hopefully this failed attempt will highlight my goal.
      tileListInstance[2].alpha = .5;
        • 1. Re: Reference an item in a TileList
          peterent Level 2
          You should never attempt to directly reference an itemRenderer in any list component. That's because we only generate itemRenderers for the visible rows of the list plus a couple extra for buffering purposes. The itemRenderers are the recycled as you scroll through the list. The Flex docs talk about this extensively.

          If you want to change an itemRenderer's alpha (or any other characteristic) you do it from within the itemRenderer code, doing so based on some value of the data. Let's say your itemRenderer is an MXML file based on Canvas and in your data record you want the alpha value set from a field called "price". You might do it like this:

          <mx:Canvas xmlns:mx="..." alpha="{data.price == 0 ? .25 : 1}" >

          So if the price is zero, then the alpha will be 0.25 otherwise it will be 1.
          • 2. Re: Reference an item in a TileList
            injpix Level 3
            Thanks again, I understand now.
            • 3. Re: Reference an item in a TileList
              Sorry, but sometime we want to aceess/control the item inside the itemRenderer.
              For example, imagine I have a video player (main.mxml) where this object class have an itemRenderer list of scenes (videoScene.mxml).
              What if I want the video while it is been play, it reach a time (let say 15 secs) where I want the selected scene of the video (that have the value of 15 secs) to be highlighted to the user that, the video is entering/playing this* scene?
              I cant do something similar as what you guys suggested here, right?
              • 4. Re: Reference an item in a TileList
                peterent Level 2
                An itemRenderer should be handling 1 thing from a list of similar things. So let's suppose you have a collection of 20 items where each item in the list has information to display a video. If the list control is sufficently large it is possible to show all 20 videos at once. But suppose it can show only 5 videos - 5 items - at once. There would only be 5 or 6 itemRenderers then. As you scroll through the list, those 5 or itemRenderers will be given new data - different items to display. So the itemRenderer must use the data it is given to show the video content.

                While a video is playing in an itemRenderer the code supporting the itemRenderer can take its direction from anything the video data, or the data for the record itself, has to offer.

                If you itemRenderer has a Timer that goes off after 15 seconds, then the itemRenderer code can respond to that and change its color, for example. But keep in mind, the user could scroll that itemRenderer out of view where the list control will then repopulate that very same itemRenderer with new data. This is how itemRenderers were designed to work in Flex.

                To sum up: the itemRenderer can do whatever it wants as long as the data for the record it is given has the information.