8 Replies Latest reply on Dec 14, 2006 6:41 PM by ntsiii

    [Binding] metadata tag


      i am new to flex, and it seems that i dont understand when the value of one property is being copied to another.

      for example

      ----------- MXML FILE ------------------------------
      public var test3:String;
      public var test2:String = test3;
      public var test1:String = test2;

      function some_function():void
      test3 = "value1";
      test3 = "value2";

      //1. what is the value of test2 and test3 at this point ?
      //2. if null -> how can i make sure that test2 and test3 are being automatically updated
      // when test1 is being changed ?

        • 1. Re: [Binding] metadata tag
          FlightGuy Level 1
          My best suggestion is that you read the section of the developer's guide on Binding Data (Chapter 37). It goes into some detail and also give examples.
          • 2. Re: [Binding] metadata tag
            ntsiii Level 3
            Actually, that should work, and it does not involve binding.
            public var test2:String = test3;
            assigns a reference to test3 to test2. Any thing using test2 is actually using test3.

            • 3. Re: [Binding] metadata tag
              eran1 Level 1
              but test3 is null when we assign its value to test2.
              in java the value of test2 will be null and stay null
              even if we change the value of test3.

              is it working differently in flex ??
              • 4. Re: [Binding] metadata tag
                ntsiii Level 3
                You are right. I am confused. I'll post back when I understand this better.

                • 5. Re: [Binding] metadata tag
                  FlightGuy Level 1
                  Strings in AS, as in Java, are immutable objects, and from a programming point of view can be considered as primitives, which are passed by value. This means that if I have the following:
                  var string1:String = "Hello";
                  var string2:String = string1;
                  string1 = "World";
                  trace(string2); // result is "Hello"

                  Binding copies properties from one object to another when a change event is dispatched from the source object. When you annotate a property with [Bindable], the compiler actually implements getter and setter methods for the property. The generated setter method first sets the backing property, and then dispatches a change event (by default it's type is "propertyChange", but you can be explicit in the [Bindable] annotation).

                  When you attach something to that binding, such as if you set an MXML property to {myBindableProperty}, flex will add an instance of ChangeWatcher, that creates a listener for that event. When it's fired, the binding instance will read the property of the source object and copy it to the target object/property.

                  You cannot attach to a bindable property in script using the {} notation, though you can
                  a) listen for the event yourself and react to it - essentially implementing the binding yourself, or
                  b) call the static method BindUtils.bindProperty(this, "test2", this, "test3"), and let flex do it for you
                  c) use the <mx:Binding> tag in mxml to do the same as b)
                  • 6. Re: [Binding] metadata tag
                    ntsiii Level 3
                    Yeah, like he said ;)

                    Seriously, thanks for the explanation, it cleared up my confusion.

                    • 7. Re: [Binding] metadata tag
                      FlightGuy Level 1
                      You're welcome - it also changed me from a "Junior Member" to a "Member", so I don't feel quite so small anymore. Some more of these and I'll be a senior member like you:) Can't wait. You're very dedicated to this for someone who doesn't have "adobe.com" in your email address! Thanks.

                      • 8. Re: [Binding] metadata tag
                        ntsiii Level 3
                        My "religion" requires that I strive to increase the total information entropy of the universe.

                        Also I have found that explaining to others and creating examples helps my knowldge become concrete.

                        So its win/win/win!