|
|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SOA World Conference
Virtualization Conference $200 Savings Expire May 16, 2008... – Register Today!
SYS-CON.TV SYS-CON.TV WEBCASTS |
MXDJ TOP LINKS YOU MUST CLICK ON ! Flex
Ask the Expert
Basics of Flex explained
By: Andrew Trice
Feb. 6, 2007 10:00 AM
Digg This!
Page 1 of 4
next page »
Andrew Trice, co-author of Flex 2 articles on Adobe's Developer Center, maintains a blog at http://www.cynergysystems.com/blogs/page/andrewtrice in which he helps orient newbies and experts alike about Flex. Web Developer's & Designer's Journal is pleased here to bring a sampler of some of his more recent shared insights.
mycomponent.myValue = 1; First, let's look at public variables...
[Bindable] It is better to use public variables when there are no additional actions that need to take place when the value has been changed. If you change the value of "myValue", the bindings will update and everything will be handled accordingly. The value will change, and anything bound to that value will change. In this case, there is no need to use getter/setter methods. Now, on to getters and setters...
[Bindable(event="myValueUpdated")] First I'll explain the [Bindable(event="myValueUpdated")] statement: This indicates that the data binding to the getter's value should be updated when the event of type "myValueUpdated" is dispatched. You'll notice that when the value is set, this event is dispatched, which would notify any components that are bound to this value. Now, the rest... The code that I showed above doesn't have any benefits over the public property; it functions in exactly the same way, but requires more code. The benefit of getter and setter functions is that they enable sequential code execution when the value is changed. You can create your components so that specific functions are executed any time that the value is accessed using get and/or set functions. Here's an example:
[Bindable(event="myValueUpdated")] In this example, every time the value is set, the numSets Number is incremented, and the myFunction() function is executed. Likewise, every time the value is accessed using the "get" method, the numGets Number is incremented, and the myOtherFunction() function is executed. There is no limit to what kind of code you can execute here. You can have it dispatch custom events, change styles, create new components, etc. This turns out to be very handy when creating custom Flex components. Page 1 of 4 next page » LATEST FLEX STORIES & POSTS
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||