Friday, March 4, 2011

Mxml and as3 confusion [simple]

Hi,

I was wondering i can call an as3 function defined in script from mxml code just like this:

<mx:Line x="translateX(xmin);" .. >


<mx:Script>
   <![CDATA[

   // do some basic math
   private function translate ...

If not possible do i have to convert everything to as3 ?

Thanks

From stackoverflow
  • Yes you can.

  • You can but a straight-up function call like that needs to go into an event attribute in MXML, i.e. "when this event is dispatched, invoke this function." The classic example being:

    <mx:Button label="Hello" click="myFunction()"/>
    

    You can use a function as you have illustrated above provided that it's in a binding expression and the arguments passed to the function are bindable:

    <mx:Line x="{positionLine(xmin)}"/>
    
    // defined somewhere in a mx:Script block
    [Bindable] private var xmin : Number;
    

0 comments:

Post a Comment