2 Replies Latest reply on Nov 27, 2009 5:44 AM by schioche

    FLEX3 : Repeater, databinding, and cast operator

    schioche

      Hello,

       

      Having encountered problems using Repeater in our enterprise project, we have decided to process heavy tests on Repeater and databinding.

      And what we have discovered is amazing!

       

      Please copy paste this code, run the app and click on the button.

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
              <mx:Script>
              <![CDATA[
                  import mx.collections.ArrayCollection;
                 
                  [Bindable]
                  private var sourceArray:ArrayCollection = new ArrayCollection([
                               new SimpleBean(),
                               new SimpleBean(),
                               new SimpleBean()
                      ]);
                 
                  public function changeValue():void{
                      var objectToModify:SimpleBean = sourceArray.getItemAt(1) as SimpleBean;
                      objectToModify.displayedName="Binding works";
                  }
              ]]>
          </mx:Script>
          <mx:VBox>
              <mx:Repeater id="rp" dataProvider="{sourceArray}">
                  <mx:Label text="{SimpleBean(rp.currentItem).displayedName}" color="green"/>
                  <mx:Label text="{(rp.currentItem as SimpleBean).displayedName}" color="red"/>
              </mx:Repeater>
          </mx:VBox>
          <mx:Button click="changeValue()"/>
      </mx:WindowedApplication>

       

      Here is the SimpleBean class:

      package
      {
          public class SimpleBean
          {
              [Bindable]
              public var displayedName:String="A default name";
          }
      }

       

      Amazing, no? It seems that the 2 cast operators behave differently inside a Repeater, and one prevents databinding to be triggered...

       

      So my question is: is it a SDK bug, or does this difference have an explanation?

        • 1. Re: FLEX3 : Repeater, databinding, and cast operator
          JabbyPandaUA Level 3

          Hi schioche,

           

          I think it is a bug in Flex 3.* SDK, confirmed the the same behaviour by me.

           

          This bug was fixed somehow in Flex 4 SDK, verified.

           

          If upgrading to Flex 4 SDK is not an option to you, then you can initiate binding manually via ActionScript, worked for me

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
              <mx:Script>
                  <![CDATA[
                      import mx.collections.ArrayCollection;
                      
                      [Bindable]
                      private var sourceArray:ArrayCollection = new ArrayCollection([
                          new SimpleBean(),
                          new SimpleBean(),
                          new SimpleBean() 
                      ]);
                      
                      public function changeValue():void{
                          var objectToModify:SimpleBean = sourceArray.getItemAt(0) as SimpleBean;
                          objectToModify.displayedName="Binding works";
                          
                          rp.executeBindings();
                      }
                  ]]>
              </mx:Script>
              <mx:VBox>
                  <mx:Repeater id="rp" dataProvider="{sourceArray}">
                      <mx:Label id="labelA" text="{SimpleBean(rp.currentItem).displayedName}" color="green"/>
                      <mx:Label id="labelB" text="{(rp.currentItem as SimpleBean).displayedName}" color="red"/>
                  </mx:Repeater>
              </mx:VBox>
              <mx:Button click="changeValue()"/>
          </mx:Application>
          
          • 2. Re: FLEX3 : Repeater, databinding, and cast operator
            schioche Level 1

            Worked for me.

             

            Thanks a lot for your quick answer.