# as3 perform function automatically?

**URL:** <https://forum.kirupa.com/t/as3-perform-function-automatically/321180>\
**Category:** flash\
**Created:** [April 12, 2011, 5:48pm UTC](https://forum.kirupa.com/t/as3-perform-function-automatically/321180 "2011-04-12T17:48:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![newbie579](https://avatars.discourse-cdn.com/v4/letter/n/ac91a4/32.png) [@newbie579](https://forum.kirupa.com/u/newbie579)\
**Post date:** [April 12, 2011, 5:48pm UTC](https://forum.kirupa.com/t/as3-perform-function-automatically/321180/1 "2011-04-12T17:48:26Z")

</div>

Hello All,

I’m new to AS3 and having a bit of trouble with listeners. The file consists of 3 buttons and 3 input fields. Clicking either of the first 2 buttons will place a specific number in one of the 2 corresponding input fields. The third button adds the previous 2 values and displays the result in the 3rd input field. The fields themselves are uneditable and only for displaying the numbers. My question is what is the correct listener/function to have the “total” function perform automatically when either of the first 2 text fields change in value…or if this is even possible…any help would be greatly appreciated…

The code below works as written…

b\_total.addEventListener(MouseEvent.MOUSE\_DOWN, total);  
b01.addEventListener(MouseEvent.MOUSE\_DOWN, button01);  
b02.addEventListener(MouseEvent.MOUSE\_DOWN, button02);  
//  
//  
var input01:String;  
var input02:String;  
var plus:Number;  
//  
//  
love01.text = “0”;  
love02.text = “0”;  
love\_total.text = “0”;  
//  
//  
function button01(event:MouseEvent):void{  
love01.text = (“14”);  
}  
function button02(event:MouseEvent):void{  
love02.text = (“8”);  
}  
function total(event:MouseEvent):void{  
input01=love01.text;  
input02=love02.text;  
plus = parseInt(input01) + parseInt(input02);  
plus.toString();  
love\_total.text = String(plus);  
}
