14 Replies Latest reply on Apr 21, 2010 7:01 AM by Jeroen Bellen

    Flex 4 databinding

    Jeroen Bellen

      Hello

       

      I guess as most people I'm just started using flex 4. When I created custom components in Flex 3, I just had to make a public member variable and make it bindable to link it. In flex 4 this still works but I'm getting a warning: 'Type Data binding will not be able to detect assignments to "...".'

       

      Does anybody know how to fix this warning?

       

      Grtz

        • 1. Re: Flex 4 databinding
          Flex harUI Adobe Employee

          Whatever variable is mentioned is apparently not

          • 2. Re: Flex 4 databinding
            SpaghettiCoder Level 3

            [Bindable]

            yourVariable

            • 3. Re: Flex 4 databinding
              David_F57 Level 5

              hi,

               

              When you get an error that indicates you have asked for something that can't be done its usually better to post the code so you can get an answer as to whether you have just made an error in the code or you are doing something thats not acceptable. As Alex already said its most likely you are binding to a non bindable variable but show the code and maybe there is an alternative way that can be offered.

               

               

              David.

              • 4. Re: Flex 4 databinding
                Jeroen Bellen Level 1

                The variables are all ready Bindable, I'll post some code.

                 

                [Bindable] public var editable:Boolean = true;

                 

                <s:TextInput id="txtDate" maxChars="10" width="75" restrict="0-9/" editable="{this.editable}" />

                 

                This code actually works, but I get the warning.

                 

                Grtz

                • 5. Re: Flex 4 databinding
                  David_F57 Level 5

                  hi,

                   

                  this code works cleanly

                   

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

                  <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                     xmlns:s="library://ns.adobe.com/flex/spark"

                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

                  <fx:Declarations>

                  <!-- Place non-visual elements (e.g., services, value objects) here -->

                  </fx:Declarations>

                  <fx:Script>

                  <![CDATA[

                  [Bindable] private var canEdit:Boolean=true;

                  ]]>

                  </fx:Script>

                  <s:CheckBox x="87" y="46" label="CheckBox" selected="{canEdit}"/>

                  <s:Button x="211" y="43" label="Button" click="canEdit=!canEdit"/>

                  <s:TextInput x="89" y="123" editable="{canEdit}"/>

                  </s:Application>

                  As I don't tend to use this. syntax or public vars or use var names the same as keywords/properties etc, any one of these could be the problem but the above is clean of warnings or errors and binding is adhered to.
                  David.

                  • 6. Re: Flex 4 databinding
                    David_F57 Level 5

                    hi,

                     

                    A little more info as you are new to flex

                     

                    <s:CheckBox x="87" y="46" label="CheckBox" selected="@{canEdit}"/>

                     

                    by placing the @ symbol in front of the binding on the checkbox it becomes 2 way so if you change the checkbox it will change the variable and vice-versa.

                     

                    David.

                    • 7. Re: Flex 4 databinding
                      Jeroen Bellen Level 1

                      Making the var private doesn't solves the problem. The warning still shows up.

                      • 8. Re: Flex 4 databinding
                        David_F57 Level 5

                        hi,

                         

                        If you paste my code into a new project does it work without warnings or errors ?, it seems something in your code is upsetting the compiler.

                         

                        David

                        • 9. Re: Flex 4 databinding
                          Jeroen Bellen Level 1

                          When I put the code directly in an application the warning is gone. If I use it in an custom component the warning persists.

                          • 10. Re: Flex 4 databinding
                            David_F57 Level 5

                            hi,

                             

                            Again with a custom component I have no warnings...what is your component base class ?

                             

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

                            <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"

                            xmlns:s="library://ns.adobe.com/flex/spark"

                            xmlns:mx="library://ns.adobe.com/flex/mx" width="284" height="104">

                            <fx:Declarations>

                            <!-- Place non-visual elements (e.g., services, value objects) here -->

                            </fx:Declarations>

                            <fx:Script>

                            <![CDATA[

                            [Bindable] public var canEdit:Boolean=true;

                            ]]>

                            </fx:Script>

                            <s:CheckBox x="31" y="14" label="CheckBox" selected="@{canEdit}"/>

                            <s:Button x="165" y="13" label="Button" click="canEdit=!canEdit"/>

                            <s:TextInput id="txtDate" maxChars="10" width="204" restrict="0-9/" editable="{canEdit}"  x="31" y="56"/>

                            </s:Group>

                            • 11. Re: Flex 4 databinding
                              Jeroen Bellen Level 1

                              My component is based on Group.

                               

                              <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"

                              xmlns:s="library://ns.adobe.com/flex/spark"

                              xmlns:mx="library://ns.adobe.com/flex/mx"

                              creationComplete="init(event)">

                              • 12. Re: Flex 4 databinding
                                David_F57 Level 5

                                hi,

                                 

                                At this point I don't know what to say, I have taken your example and basically had it working in components, sub components, two-way binding, binding between parent and component and can not reproduce your warning, the only thing that I can think of is that somewhere in your code you are tripping up the compiler which cuases the warning.

                                 

                                David.

                                • 13. Re: Flex 4 databinding
                                  Jeroen Bellen Level 1

                                  I found the problem! The name of the bindable variable can't be the same as the property your binding to.

                                   

                                  [Bindable] public var canEdit:Boolean=true;

                                  <s:TextInput id="txtDate" maxChars="10" width="75" restrict="0-9/" editable="{canEdit}" />

                                   

                                  is valid whereas

                                   

                                   

                                  [Bindable] public var editable =true;

                                   

                                  <s:TextInput id="txtDate" maxChars="10" width="75" restrict="0-9/" editable="{editable}" />

                                   

                                  isn't.

                                   

                                  Grtzz and thanks for your help

                                  • 14. Re: Flex 4 databinding
                                    David_F57 Level 5

                                    hi,

                                     

                                    I told you about 6 posts ago about vars that have the same name as property I though you changed it.

                                     

                                     

                                    David.