Search the web
Sign In
New User? Sign Up
flexcoders · RIA Development with Adobe Flex
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Databinding Custom Event   Topic List   < Prev Topic  |  Next Topic >
Reply | Forward  | 
RE: [flexcoders] Databinding Custom Event

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



Wed Nov 29, 2006 4:02 am

triceam01
Offline Offline
Send Email Send Email

Forward
 | 
Expand Messages Author Sort by Date

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
bjorn.schult...
Offline Send Email
Nov 29, 2006
2:01 am

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...
Andrew Trice
triceam01
Offline Send Email
Nov 29, 2006
4:16 am

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...
Bjorn Schultheiss
bjorn.schult...
Offline Send Email
Nov 29, 2006
4:49 am

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...
Bjorn Schultheiss
bjorn.schult...
Offline Send Email
Nov 30, 2006
3:42 am

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.. ... ...
Bjorn Schultheiss
bjorn.schult...
Offline Send Email
Nov 30, 2006
6:27 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help