Why not just do something like this:

<mx:Script>
    <![CDATA[
        [Bindable]
        public var numberToDisplay:Number;

        private function formatBalance( balance:Number ) :String
        {
            // return formatted string here
        }
    ]]>
</mx:Script>
<mx:Label id="NumberDisplay" text="Your current balance is 
{formatBalance(numberToDisplay)}" />


> 
> From: "longhairedsi" <[EMAIL PROTECTED]>
> Date: 2007/03/14 Wed PM 04:30:16 CST
> To: [email protected]
> Subject: [flexcoders] Binding - Fire a function on variable change (noob)
> 
> 
> 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
> 
> 
> 

--
John Mark Hawley
The Nilbog Group
773.968.4980 (cell)



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Great things are happening at Yahoo! Groups.  See the new email design.
http://us.click.yahoo.com/lOt0.A/hOaOAA/yQLSAA/nhFolB/TM
--------------------------------------------------------------------~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/flexcoders/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to