8 Replies Latest reply on May 16, 2009 11:24 AM by kergadic35

    databinding refresh problem

    kergadic35

      Hi,

       

      I am a Flex Beginner and I have a problem with data binding. I have this small program :

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Script>
              <![CDATA[           
                  [Bindable] public var valeur:String;
              ]]>
          </mx:Script>

       

          <mx:ViewStack id="mainViewStack"  width="100%" height="100%">
              <mx:Panel id="panel1">
                      <mx:TextInput id="text1"/>
                      <mx:Button label="A" click="valeur='test';mainViewStack.selectedIndex=1;"/>
              </mx:Panel>
              <mx:Panel id="panel2">
                  <mx:TextInput id="text2" text="{valeur}"/>
                  <mx:Button label="B" click="mainViewStack.selectedIndex=0;"/>
              </mx:Panel>
          </mx:ViewStack>
      </mx:Application>

       

      - I switch between 2 panels ('A' button).

      - When I switch from panel1 to panel2 (click event), I change 'valeur' variable to 'test' (with databinding, text2 is updated).

      - After that, I modify manually the text2 valeur (for example "valeur123").

      - I switch from panel2 to panel1 ('B' button)

      - I switch one more time from panel1 to panel2 ('A' button)

       

      => and this time, the 'text2' TextInput is not updated ; the value does not change (still 'valeur123').

       

      So why the databinding does not work in that case ?

       

      Thank you for your help.

       

      Regards

       

      Greg

        • 1. Re: databinding refresh problem
          ATIF FAROOQ Level 3

          hi,

             you are trying to do 2-way data binding which is not yet implemented in flex 3 sdk you will need to wait for flex 4 to do that.

          • 2. Re: databinding refresh problem
            Michael Borbor Level 4

            probably because when you change manually the text you are overriding 

            the binding.

             

            Sincerely,

             

            Michael

             

            El 16/05/2009, a las 11:32, kergadic35 <forums@adobe.com> escribió:

             

            >

            Hi,

            >

            I am a Flex Beginner and I have a problem with data binding. I have 

            this small program :

            >

            <?xml version="1.0" encoding="utf-8"?>

            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml

            layout="absolute">

                <mx:Script>

                    <![CDATA[

                        public var valeur:String;

                    ]]>

                </mx:Script>

            >

                <mx:ViewStack id="mainViewStack"  width="100%" height="100%">

                    <mx:Panel id="panel1">

                            <mx:TextInput id="text1"/>

                            <mx:Button label="A" 

            click="valeur='test';mainViewStack.selectedIndex=1;"/>

                    </mx:Panel>

                    <mx:Panel id="panel2">

                        <mx:TextInput id="text2" text=""/>

                        <mx:Button label="B" 

            click="mainViewStack.selectedIndex=0;"/>

                    </mx:Panel>

                </mx:ViewStack>

            </mx:Application>

            >

            - I switch between 2 panels ('A' button).

            - When I switch from panel1 to panel2 (click event), I change 

            'valeur' variable to 'test' (with databinding, text2 is updated).

            - After that, I modify manually the text2 valeur (for example 

            "valeur123").

            - I switch from panel2 to panel1 ('B' button)

            - I switch one more time from panel1 to panel2 ('A' button)

            >

            => and this time, the 'text2' TextInput is not updated ; the value 

            does not change (still 'valeur123').

            >

            So why the databinding does not work in that case ?

            >

            Thank you for your help.

            >

            Regards

            >

            Greg

            >

            • 3. Re: databinding refresh problem
              kergadic35 Level 1

              Are you sure ?

               

              It seems to me that there is only a 1-way databinding, isn't it ?

              • 4. Re: databinding refresh problem
                Michael Borbor Level 4

                Yes that's right in The next version of the flex sdk there's two way 

                binding, but as Spiderman's grand pa said with great power comes great 

                responsability.

                 

                Sincerely,

                 

                Michael

                 

                El 16/05/2009, a las 12:19, kergadic35 <forums@adobe.com> escribió:

                 

                >

                Are you sure ?

                >

                It seems to me that there is only a 1-way databinding, isn't it ?

                >

                • 5. Re: databinding refresh problem
                  kergadic35 Level 1

                  Excuse me I was not clear.

                   

                  I wanted to say that it seems to me that there is only a one-way binding in my program

                   

                  Where do you see a 2-way binding in my code ?

                   

                  Thanks

                  • 6. Re: databinding refresh problem
                    Michael Borbor Level 4

                    Actually the Flex Sdk 3.* doesn't support two way binding so even if 

                    you want to you can develop a two way binding app.

                     

                    I didn't say your app implemented two way binding.

                     

                    Sincerely,

                     

                    Michael

                     

                    El 16/05/2009, a las 12:28, kergadic35 <forums@adobe.com> escribió:

                     

                    >

                    Excuse me I was not clear.

                    >

                    I wanted to say that it seems to me that there is only a one-way 

                    binding in my program

                    >

                    Where do you see a 2-way binding in my code ?

                    >

                    Thanks

                    >

                    • 7. Re: databinding refresh problem
                      ATIF FAROOQ Level 3

                      yes you were not trying to bind your data in 2 way but i said that because suppose if you have two way data binding support right now then you will not be facing that problem.consider the following two lines which suppose to execute two way data binding

                       

                        <mx:Binding source="valeur" destination="text2.text"/>
                        <mx:Binding destination="valeur" source="text2.text"/>
                      

                       

                      try running the following application and see what happens

                      <?xml version="1.0" encoding="utf-8"?>
                      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                          <mx:Script>
                              <![CDATA[            
                                  [Bindable] public var valeur:String;
                              ]]>
                          </mx:Script>
                          <mx:ViewStack id="mainViewStack"  width="100%" height="359" creationPolicy="all">
                              <mx:Panel id="panel1">
                                      <mx:TextInput id="text1"/>
                                      <mx:Button label="A" click="valeur='test';mainViewStack.selectedIndex=1;"/>
                              </mx:Panel>
                              <mx:Panel id="panel2">
                                  <mx:TextInput id="text2"/>
                                  <mx:Button label="B" click="mainViewStack.selectedIndex=0;"/>
                              </mx:Panel>
                          </mx:ViewStack>
                          <mx:Label x="55" y="393"  width="198" height="40"/>
                          <mx:Binding source="valeur" destination="text2.text"/>
                          <mx:Binding destination="valeur" source="text2.text"/>
                      </mx:Application>
                      
                      • 8. Re: databinding refresh problem
                        kergadic35 Level 1

                        Nice ! It works

                         

                        Thank you very much for your help !

                         

                        Regards

                         

                        Greg