logo

Data Binding Gone Wild!

logo

The ability to base a property of an object off a dynamically changing value is a benefit of data binding that is often unknown or overlooked by Flex developers. However it is an extremely valuable feature and can save a lot of time coding and handling various events, not to mention much cleaner code! This is particularly true for those properties requiring a boolean, such as ‘enabled’ or ‘visible’. The toggle can be done during execution based on a certain sequence of events. The code returning the value for the property can be included within the binding brackets in the case where minimal code is needed to derive the value, or via a function call that returns the value. The following code excerpt shows how this can easily be done in your Flex application. It basically sets the ‘enable’ property of the Delete button to a dynamically derived value that indicates whether a row in the grid has been clicked. Simple as that!



	
		

	
		
			
				
				
				
				
			
		
		
	

Comments welcome :)

  • hair removal electrolysis at home prices
  • laser best hair removal products
  • laser hair removal reviews cost
  • best hair removal laser prices
  • cost of laser hair removal reviews
  • effective hair removal reviews
  • what is laser ultrasonic hair removallaser for ultrasonic hair removal cream
  • Share

    4 Responses to “Data Binding Gone Wild!”

    1. [...] Schinsky, a Flex/AIR developer and new blogger, just posted an interesting example at http://devgirl.wordpress.com/2008/10/29/data-binding-gone-wild .  Check out the mx:Button tag enabled [...]

    2. James Ward says:

      Cool stuff! I’ve found that using ternary operators in binding expressions is also very useful. Such as:

      label=”{playing ? ‘Stop’ : ‘Play’}”

      -James

    3. Marcel Boucher says:

      Very good article DevGirl. Data Binding can be extremely effective when you are building applications that require unit testing. Using this approach, you can easily create ActionScript classes that can be detached from UI and tested separately.

      Nice job.

    4. Another tip- If you’re using the same binding expression over and again, put it in a variable, and bind to that.

      Instead of having 5 different components each having enabled=”{ something && somethingElse(foo) }”

      { something && somethingElse(foo) }

      And then your actual GUI components can bind to “{ isBlue }” cutting down on cruft and improving readability.

      You can also replace the MXML definition of “isBlue” with anything else you like down the track (perhaps a [Bindable("isBlueChanged")] get function)…

    5. Another tip- If you’re using the same binding expression over and again, put it in a variable, and bind to that.

      Instead of having 5 different components each having enabled=”{ something && somethingElse(foo) }”

      <mx:Boolean id=”isBlue”>{ something && somethingElse(foo) }</mx:Boolean>

      And then your actual GUI components can bind to “{ isBlue }” cutting down on cruft and improving readability.

      You can also replace the MXML definition of “isBlue” with anything else you like down the track (perhaps a [Bindable("isBlueChanged")] get function)…

    Leave a Reply

    logo
    logo
    Powered by WordPress | Designed by Elegant Themes