views:

361

answers:

2

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

A: 

Yes you can.

defmeta
+5  A: 

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;
cliff.meyers