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

<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;
     }

     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

Reply via email to