I'm not very familiar with flash so this is my current problem to deal with. I've found some code but it's in actionscript 2.0
, when i tried to run it in my project, it shows the following error.
Here are my errors: 1. Scene 1, Layer 'Layer 2', Frame 1, Line 6
1067: Implicit coercion of a value of type Number to an unrelated type flash.text:TextField.
1180: Call to a possibly undefined method on.
1120: Access of undefined property release.
var weight_BMI;
var height_BMI;
var BMI_FINAL;
total_BMI=Number(weight_BMI.text)/(Number(height_BMI.text)*Number(height_BMI.text));
on(release){
trace(weight_BMI.text)
trace(height_BMI.text)
trace(BMI_FINAL)
}
AS2
is very different from AS3
. AS3
works by using methods (in the same way as Java
, for example). See the code below as an example (note, you may need to edit/rename your fields to get it to compile)
It works by attaching a Click EventListener
to your calculate button which when triggered it runs the calculateBMI
method. This method then performs the calculation and prints the result to your text field.
var myBmi:TextField;
var total_BMI:Number;
function calculateBMI(e:MouseEvent):void
{
total_BMI = Number(weight_BMI.text)/(Number(height_BMI.text)*Number(height_BMI.text));
myBmi.text = String(total_BMI);
}
btnCalculate.addEventListener(MouseEvent.CLICK, calculateBMI);