Mar
16
Arcadio March 16, 2009 9:14 pm

In a flex component which expose a calculated property is necessary to implement a system to listening internal changes and dispatch them to the main application. It could be achieved with accessors methods bindabled with an internal event when it must recalculate the property.

An example:

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">
	<mx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			[Bindable]
			private var items1:ArrayCollection=new ArrayCollection([
				2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010
			]);
			[Bindable]
			private var items2:ArrayCollection=new ArrayCollection([
				"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"
			]);

			private var _myDate:Date;
			[Bindable ("change")]
			public function set myDate(value:Date):void {
				_myDate=value;
				year.selectedItem=int(value.getFullYear());
				month.selectedIndex=value.getMonth();
			}
			public function get myDate():Date {
				_myDate.setFullYear(year.selectedItem, month.selectedIndex+1, 0);
				return _myDate;
			}
		]]>
	</mx:Script>

	<mx:ComboBox id="year" dataProvider="{items1}" change="{dispatchEvent(new Event('change'))}"/>
	<mx:ComboBox id="month" dataProvider="{items2}" change="{dispatchEvent(new Event('change'))}"/>
</mx:HBox>

Bindable only in set method.

  • Share/Bookmark

Post a comment



Creative Commons License
This blog is under Creative Commons licence, unless indicated otherwise.
Special thanks to Mark James for the icon set used in this blog.