Call your method in Button click event

<?xml version="1.0" encoding="UTF-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
private function calculateFactorial(n:String):String
{
var y:Number=1;
for (var x:Number = 1;x <= Number(n); x++) {
y = y * x;
}
return String(y);
}
</mx:Script>
<mx:Panel title="Calculate Factorial">
<mx:HBox>
<mx:Label text="Input:"/>
<mx:TextInput id="textArea1" text="1"/>
<mx:Button id="button1" label="Calculate" click="result.text=calculateFactorial(textArea1.text)"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Factorial:"/>
<mx:Label id="result"/>
</mx:HBox>
</mx:Panel>
</mx:Application>
Related examples in the same category