2 Replies Latest reply on Jan 14, 2010 11:26 PM by archemedia

    Data access in List Based components

    kiran7881 Level 1

      Hello ,


      I am working with List Based components , List and a Combobox for practice purpose.


      I had written a Event Listener as  :



      public function handleList(event:ListEvent):void







      Why is that both of them are having two different ways of accessing Data .


      event.itemRenderer.data.toString() is for List and


      event.target.selectedItem.toString() is for ComboBox ??


      and what i observered is that  event.target.selectedItem.toString() is working for both of them , but event.itemRenderer.data.toString() is working with List only .




        • 1. Re: Data access in List Based components
          cheftimo Level 2

          I am no real expert on this, but I think you may be a little confused, as I was when I first started learning Flex: the list is a control, the itemRenderer is normally a container – two different animals.


          The itemRenderer is a property of the list and all of that renderer's data is available in a variable called 'data' – it does not have a selectedIndex or any of many properties that controls have.


          HTH. Regards,



          • 2. Re: Data access in List Based components
            archemedia Level 4

            You shouldn't use the itemRenderer property, at least not in this case. The list component has a selectedItem property too! Maybe you should check the currentTarget property in your event instead of the target property. In case of the list component, these two properties will have different values. When you click on a list component, you actually click on the label of the component, which is the itemRenderer. Therefore, event.target will hold a reference to this itemRenderer instead of the tree component itself! You can access the item component through event.currentTarget. So, to get the selectedItem in your list component, use event.currentTarget.selectedItem.