Loading ...
Sorry, an error occurred while loading the content.
 

RE: [flexcoders] Databinding Custom Event

Expand Messages
  • Andrew Trice
    The benefit is that your getter function will be bound to that event, so any time that event is dispatched, the data binding is updated. In this example, it
    Message 1 of 5 , Nov 28, 2006

      The benefit is that your getter function will be bound to that event, so any time that event is dispatched, the data binding is updated.  In this example, it doesn’t really stand out that this is a great thing.  Let’s say that there is also a “get lastname” function that is similar to your firstname function, and add an updateNames function, so we have this…

       

      [Bindable(event="MyEvent")]

      public function set firstname(value: String):void

      {

                  _firstname = value;

                  dispatchEvent( new FlexEvent('MyEvent') );

      }

      public function get firstname(): String

      {

                  return _firstname;

      }

      private var _firstname:String;

       

      [Bindable(event="MyEvent")]

      public function set lastname(value: String):void

      {

                  _lastname = value;

                  dispatchEvent( new FlexEvent('MyEvent') );

      }

      public function get lastname (): String

      {

                  return _lastname;

      }

      private var _lastname:String;

       

      public function updateNames ( myUpdateObject : Object ): void

      {

                  _firstname = myUpdateObject.firstname;

                  _lastname  = myUpdateObject.lastname

                  dispatchEvent( new FlexEvent('MyEvent') );

      }

       

      The updateNames function dispatches a single event, which updates the bindings on both of your “getter” functions.   Now, the real benefit of “set” functions is that you can programmatically execute code when a value is updated.  Your names example doesn’t take full advantage of the capabilities.  The “set” function is better suited for when you have other functions that should be executed any time that your “set” is updated.

       

      [Bindable(event="MyEvent")]

      public function set firstname(value: String):void

      {

                  _firstname = value;

             //execute some code here

             doSomething();

             doSomethingElse();

             doAnotherThing();

                  dispatchEvent( new FlexEvent('MyEvent') );

      }

       

      In this example, the data binding gets updated after the other functions have been executed.  This technique is VERY useful when developing flex components.  For instance, you can have a function on a custom component that extends a text box such as:

       

      override public function set text( value : String ) : void

       

      And you want other properties to be updated when text has been updated, so you setup your “set” function like this:

       

      override public function set text( value : String ) : void

      {

                  this.updated = true;

                  resetComponentState();

                  super.text = value;

      }

       

      Hope that helps,

      -Andy

      _____________________________________

      Andrew Trice

      Cynergy Systems, Inc.

      http://www.cynergysystems.com

       

      Blog: http://www.cynergysystems.com/blogs/page/andrewtrice

      Email: andrew.trice@...

      Office: 866-CYNERGY 

       


      From: flexcoders@yahoogroups.com [mailto: flexcoders@yahoogroups.com ] On Behalf Of Bjorn Schultheiss
      Sent: Tuesday, November 28, 2006 9:02 PM
      To: flexcoders@yahoogroups.com
      Subject: [flexcoders] Databinding Custom Event

       

      Hey,

       

      What if any benefits are there to defining a custom event type for your databinding?

      ie:

      [Bindable(event="MyEvent")]

      public function set firstname(value: String):void

      {

                  _firstname = value;

                  dispatchEvent( new FlexEvent('MyEvent') );

      }

      public function get firstname(): String

      {

                  return _firstname;

      }

      private var _firstname:String;

       

      vs

      [Bindable]

      public var lastname:String;

       

      Regards,

      Bjorn

    • Bjorn Schultheiss
      Thanks alot, A great answer, explained clearly. Cheers :) ... Thanks alot, A great answer, explained clearly. Cheers :) On 29/11/2006, at 3:02 PM, Andrew Trice
      Message 2 of 5 , Nov 28, 2006
        Thanks alot,

        A great answer, explained clearly.

        Cheers :)

        On 29/11/2006, at 3:02 PM, Andrew Trice wrote:


        The benefit is that your getter function will be bound to that event, so any time that event is dispatched, the data binding is updated.  In this example, it doesn’t really stand out that this is a great thing.  Let’s say that there is also a “get lastname” function that is similar to your firstname function, and add an updateNames function, so we have this…

         

        [Bindable(event="MyEvent")]

        public function set firstname(value:String):void

        {

                    _firstname = value;

                    dispatchEvent( new FlexEvent('MyEvent') );

        }

        public function get firstname():String

        {

                    return _firstname;

        }

        private var _firstname:String;

         

        [Bindable(event="MyEvent")]

        public function set lastname(value:String):void

        {

                    _lastname = value;

                    dispatchEvent( new FlexEvent('MyEvent') );

        }

        public function get lastname ():String

        {

                    return _lastname;

        }

        private var _lastname:String;

         

        public function updateNames ( myUpdateObject : Object ):void

        {

                    _firstname = myUpdateObject.firstname;

                    _lastname  = myUpdateObject.lastname

                    dispatchEvent( new FlexEvent('MyEvent') );

        }

         

        The updateNames function dispatches a single event, which updates the bindings on both of your “getter” functions.   Now, the real benefit of “set” functions is that you can programmatically execute code when a value is updated.  Your names example doesn’t take full advantage of the capabilities.  The “set” function is better suited for when you have other functions that should be executed any time that your “set” is updated.

         

        [Bindable(event="MyEvent")]

        public function set firstname(value:String):void

        {

                    _firstname = value;

               //execute some code here

               doSomething();

               doSomethingElse();

               doAnotherThing();

                    dispatchEvent( new FlexEvent('MyEvent') );

        }

         

        In this example, the data binding gets updated after the other functions have been executed.  This technique is VERY useful when developing flex components.  For instance, you can have a function on a custom component that extends a text box such as:

         

        override public function set text( value : String ) : void

         

        And you want other properties to be updated when text has been updated, so you setup your “set” function like this:

         

        override public function set text( value : String ) : void

        {

                    this.updated = true;

                    resetComponentState();

                    super.text = value;

        }

         

        Hope that helps,

        -Andy

        _____________________________________

        Andrew Trice

        Cynergy Systems, Inc.

        http://www.cynergysystems.com

         

        Blog: http://www.cynergysystems.com/blogs/page/andrewtrice

        Email: andrew.trice@cynergysystems.com

        Office: 866-CYNERGY 

         


        From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Bjorn Schultheiss
        Sent: Tuesday, November 28, 2006 9:02 PM
        To: flexcoders@yahoogroups.com
        Subject: [flexcoders] Databinding Custom Event

         

        Hey,

         

        What if any benefits are there to defining a custom event type for your databinding?

        ie:

        [Bindable(event="MyEvent")]

        public function

      • Bjorn Schultheiss
        champion answer, ill pass on the good info ... champion answer, ill pass on the good info  On 29/11/2006, at 3:02 PM, Andrew Trice wrote: The benefit is that
        Message 3 of 5 , Nov 28, 2006
          champion answer, ill pass on the good info 

          On 29/11/2006, at 3:02 PM, Andrew Trice wrote:


          The benefit is that your getter function will be bound to that event, so any time that event is dispatched, the data binding is updated.  In this example, it doesn’t really stand out that this is a great thing.  Let’s say that there is also a “get lastname” function that is similar to your firstname function, and add an updateNames function, so we have this…

           

          [Bindable(event="MyEvent")]

          public function set firstname(value:String):void

          {

                      _firstname = value;

                      dispatchEvent( new FlexEvent('MyEvent') );

          }

          public function get firstname():String

          {

                      return _firstname;

          }

          private var _firstname:String;

           

          [Bindable(event="MyEvent")]

          public function set lastname(value:String):void

          {

                      _lastname = value;

                      dispatchEvent( new FlexEvent('MyEvent') );

          }

          public function get lastname ():String

          {

                      return _lastname;

          }

          private var _lastname:String;

           

          public function updateNames ( myUpdateObject : Object ):void

          {

                      _firstname = myUpdateObject.firstname;

                      _lastname  = myUpdateObject.lastname

                      dispatchEvent( new FlexEvent('MyEvent') );

          }

           

          The updateNames function dispatches a single event, which updates the bindings on both of your “getter” functions.   Now, the real benefit of “set” functions is that you can programmatically execute code when a value is updated.  Your names example doesn’t take full advantage of the capabilities.  The “set” function is better suited for when you have other functions that should be executed any time that your “set” is updated.

           

          [Bindable(event="MyEvent")]

          public function set firstname(value:String):void

          {

                      _firstname = value;

                 //execute some code here

                 doSomething();

                 doSomethingElse();

                 doAnotherThing();

                      dispatchEvent( new FlexEvent('MyEvent') );

          }

           

          In this example, the data binding gets updated after the other functions have been executed.  This technique is VERY useful when developing flex components.  For instance, you can have a function on a custom component that extends a text box such as:

           

          override public function set text( value : String ) : void

           

          And you want other properties to be updated when text has been updated, so you setup your “set” function like this:

           

          override public function set text( value : String ) : void

          {

                      this.updated = true;

                      resetComponentState();

                      super.text = value;

          }

           

          Hope that helps,

          -Andy

          _____________________________________

          Andrew Trice

          Cynergy Systems, Inc.

          http://www.cynergysystems.com

           

          Blog: http://www.cynergysystems.com/blogs/page/andrewtrice

          Email: andrew.trice@cynergysystems.com

          Office: 866-CYNERGY 

           


          From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Bjorn Schultheiss
          Sent: Tuesday, November 28, 2006 9:02 PM
          To: flexcoders@yahoogroups.com
          Subject: [flexcoders] Databinding Custom Event

           

          Hey,

           

          What if any benefits are there to defining a custom event type for your databinding?

          ie:

          [Bindable(event="MyEvent")]

          public function set

        • Bjorn Schultheiss
          Weird i haven t posted to the list all day, yet i have had 2 messages go through, hmm... Anyway as you can see i m grateful to Andrew s reply.. ...
          Message 4 of 5 , Nov 29, 2006
            Weird i haven't posted to the list all day, yet i have had 2 messages go through, hmm...
            Anyway as you can see i'm grateful to Andrew's reply..

            On 29/11/2006, at 3:27 PM, Bjorn Schultheiss wrote:

            Thanks alot,


            A great answer, explained clearly.

            Cheers :)

            On 29/11/2006, at 3:02 PM, Andrew Trice wrote:


            The benefit is that your getter function will be bound to that event, so any time that event is dispatched, the data binding is updated.  In this example, it doesn’t really stand out that this is a great thing.  Let’s say that there is also a “get lastname” function that is similar to your firstname function, and add an updateNames function, so we have this…

             

            [Bindable(event="MyEvent")]

            public function set firstname(value:String):void

            {

                        _firstname = value;

                        dispatchEvent( new FlexEvent('MyEvent') );

            }

            public function get firstname():String

            {

                        return _firstname;

            }

            private var _firstname:String;

             

            [Bindable(event="MyEvent")]

            public function set lastname(value:String):void

            {

                        _lastname = value;

                        dispatchEvent( new FlexEvent('MyEvent') );

            }

            public function get lastname ():String

            {

                        return _lastname;

            }

            private var _lastname:String;

             

            public function updateNames ( myUpdateObject : Object ):void

            {

                        _firstname = myUpdateObject.firstname;

                        _lastname  = myUpdateObject.lastname

                        dispatchEvent( new FlexEvent('MyEvent') );

            }

             

            The updateNames function dispatches a single event, which updates the bindings on both of your “getter” functions.   Now, the real benefit of “set” functions is that you can programmatically execute code when a value is updated.  Your names example doesn’t take full advantage of the capabilities.  The “set” function is better suited for when you have other functions that should be executed any time that your “set” is updated.

             

            [Bindable(event="MyEvent")]

            public function set firstname(value:String):void

            {

                        _firstname = value;

                   //execute some code here

                   doSomething();

                   doSomethingElse();

                   doAnotherThing();

                        dispatchEvent( new FlexEvent('MyEvent') );

            }

             

            In this example, the data binding gets updated after the other functions have been executed.  This technique is VERY useful when developing flex components.  For instance, you can have a function on a custom component that extends a text box such as:

             

            override public function set text( value : String ) : void

             

            And you want other properties to be updated when text has been updated, so you setup your “set” function like this:

             

            override public function set text( value : String ) : void

            {

                        this.updated = true;

                        resetComponentState();

                        super.text = value;

            }


            (Message over 64 KB, truncated)

          Your message has been successfully submitted and would be delivered to recipients shortly.