3 Replies Latest reply on Dec 25, 2010 9:30 AM by paolo.anghileri

    Simulating click on a list

    paolo.anghileri

      I have a list with a form aside; in my app when I click on the list I display the items in the form.

      When I save the form data I reload the list so I miss the focus on it's selectedindex.

       

      I tried saving the selectedindex in a variable and setting in again after the reassigning of the dataprovider to the list but my problem is different: I have to simulate a click on the selectedindex to run the function that runs at the onclick event on the list and loads the data into the form.

       

      Can anyone help me on this?

       

      Thanks

       

      Paolo

        • 1. Re: Simulating click on a list
          saisri2k2 Level 4

          You click handler will be something like

           

           

          public function onClick(evt:Event):void{
          
          // some logic
          }
          

           

           

          change the above method to this below

           

          public function onClick(evt:Event=null):void{
          
          // some logic
          }
          

           

           

          see the arguments it is taking now, event is optional(we set it to null), now, you can call it after the data reload in the list like following

           

          list.selectedIndex =SOME_STORED_INDEX;
          onClick(); //here we dont have to pass the event, it is optional
          
          1 person found this helpful
          • 2. Re: Simulating click on a list
            paolo.anghileri Level 1

            Thanks, your answer was helpful and inside the road I was following (storing the index),

            but how to set the focus to the selectedItem in the list?

            Setting the focus to it will help the user to see the item in the list he is working on.

             

            lst.setFocus() does not work.

             

            lst.selectedIndex.setFocus() will of course  not work because selectedindex is a number and not a class.

             

             

            Thx

             

            Paolo

            • 3. Re: Simulating click on a list
              saisri2k2 Level 4
              var array:ArrayCollection;//your data collection
              var list:List ;//your list
              
              someFunction(){//this is the function wehere you reload dta etc.,
                                  list.selectedItem = array.getItemAt(SOME_STORED_INDEX);
                                  list.invalidateProperties()
              
              
              }