Hi, longhairedsi wrote: > I have a custom component with a bindable property. I want a internal > function to fire everytime this property changes. I was wondering the > best way to do this was. Do I create a custom event that fires when the > property changes? Or do I call the function from the property "set" > method? What would be the best way to achieve this? Here's a simple > example >
How about adding an event listener which uses the formatNumberDisplay method as the event handler? See below. If you call the method directly from your setter then you wont get to handle that event elsewhere if you need to. > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml > <http://www.adobe.com/2006/mxml> " > creationComplete="formatNumberDisplay()" > > <mx:Script> > <![CDATA[ > [Inspectable(defaultValue=10)] > private var _numberToDisplay:Number = 10; > > public function set numberToDisplay(myNumber:Number){ > _numberToDisplay = myNumber > dispatchEvent(new Event("changeNumberToDisplay")); > } > > [Bindable(event="changeNumberToDisplay")] > public function get numberToDisplay():Number{ > return _numberToDisplay; > } > addEventListener("changeNumberToDisplay", formatNumberDisplay); > public function formatNumberDisplay(){ > if(_numberToDisplay < 0){ > NumberDisplay.setStyle("color", 0xCC3333) > }else{ > NumberDisplay.setStyle("color", 0x33CC33) > } > } > ]]> > </mx:Script><mx:Label id="NumberDisplay" text="Your current balance is > {numberToDisplay}" /> > </mx:Panel> > > I want the "formatNumberDisplay()" function to fire when > "numberToDisplay" changes. This change already fires the > "changeNumberToDisplay event", how do I capture that here? > > Cheers Si > HTH. regards, shaun

