In my mxml file, I'm doing some calculations in the script tag, and binding them to a custom component.
<fx:Script>
<![CDATA[
[Bindable] public var calc1:Number;
[Bindable] public var calc2:Number;
private function init():void {
calc1 = //calculation;
calc2 = //calculation;
}
]]>
</fx:Script>
<mycomp:Ball compfield1="{calc1}" compfield2="{calc2}"/>
The problem is that the mxml component is being created before the actionscript is run. So when the component is created, it actually doesn't get calc1
and calc2
and it fails from that point. I know that binding happens after that, but the component and its functions have already started and have run with the null or 0 initial values.
My solution was to create the component also in actionscript right after calc1
and calc2
have been created. This way I get to control precisely when it's created
<fx:Script>
<![CDATA[
[Bindable] public var calc1:Number;
[Bindable] public var calc2:Number;
private function init():void {
calc1 = //calculation;
calc2 = //calculation;
var Ball:Ball = new Ball(calc1, calc2);
}
]]>
</fx:Script>
but this is creating all kinds of other problems due to the way I've set up the component.
Is there a way I can still use mxml to create the component, yet control that it the <myComp:Ball>
gets created only after init()
is run and calc1
calc2
evaluated?