Trying to complete a simple class example
Hi, in an effort to better understand AS3 classes I have set up a little example for myself which consists of a Flash file containing three text input boxes and a button.
The idea is that the user enters numbers in the first two text boxes then clicks the "Calc" button. The program sends the numeric data for processing and returns the sum of the two numbers appearing in the third text box. At the stage that I'm at I keep getting an error message which states: "Implicit coercion of a value of type Number to an unrelated type Function." Can someone explain to me where I've gone wrong? Here is my code.
Code from Calc.fla
//Creates an object from the class called mySample
var externalFile:mySample = new mySample();
//allows the program to read the text box as a number
var num1 = Number(txtBox1.text)
var num2 = Number(txtBox2.text)
//Button event listener
btnCalc.addEventListener(MouseEvent.CLICK,externalFile.addNumbers(num1, num2));
Code from mySample.as
package {
public class mySample {
//set a few number variables
var num1:Number = 0;
var num2:Number = 0;
var answer:Number = 0;
//create a function
public function addNumbers(num1, num2):Number {
answer = num1 + num2;
return answer; //this function returns something that can be used elsewhere
}
}
}
