1 Reply Latest reply on Sep 1, 2010 12:30 AM by bmilesp

    spark list- bindable setter not working?

    bmilesp Level 1

      Hello,

      I have an XML node bound to a custom variable in a custom list component with an itemRenderer (called ShelvesList) like so:

       

                [Bindable]
                  public function set selectedId(id:Number):void{
                     var i:Number = 0;
                      for each (var item:* in dataProvider){
                          if(item.@id == id){
                              selectedIndex = i;
                          }
                      i++;}
                  }
                 
                  public function get selectedId():*{
                      return selectedItem.@id;
                  }

       

       

      and in my app i have this:

       

      <components:ShelvesList id="shelves" selectedId="@{bookModel.book.shelf_id}"/>

       

      where bookModel is an XML object.

       

      what is strange is that when i change bookModel.book.shelf_id it will not update shelves.selectedId. but if i remove [Bindable] from the setter it WILL update bookModel.book.shelf_id.

       

      however, if [Bindable] is removed from the setter and i change selectedId, it will NOT update the bookModel.book.shelf_id, even though i have two-way binding set.

       

      Is this a bug or am i overlooking something obvious? thank you for your help.

        • 1. Re: spark list- bindable setter not working?
          bmilesp Level 1

          nevermind, i figured it out! need to set [Bindable] on the getter, and add en event handler on change:

           

          [Bindable("selectedIdChanged")]
          public function get selectedId():*{
                          return selectedItem.@id;
                      }
                     
                      public function set selectedId(id:Number):void{
                          var i:Number = 0;
                          for each (var item:* in dataProvider){
                              if(item.@id == id){
                                  selectedIndex = i;
                              }
                          i++;}
                      }
                     
                      protected function setSelectedId(event):void{
                          selectedId = Number(selectedItem.@id);
                          dispatchEvent(new Event("selectedIdChanged"));
                      }

           

          then on the change event, use setSelectedId. -b