简体   繁体   English

如何使用 actionscript 3.0 在 flash cs5.5 中创建 bmi 计算器?

[英]How to create bmi calculator inside flash cs5.5 using actionscript 3.0?

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.我找到了一些代码,但它在actionscript 2.0 ,当我尝试在我的项目中运行它时,它显示以下错误。

Here are my errors: 1. Scene 1, Layer 'Layer 2', Frame 1, Line 6以下是我的错误: 1. 场景 1,图层“第 2 层”,第 1 帧,第 6 行

1067: Implicit coercion of a value of type Number to an unrelated type flash.text:TextField. 1067:将 Number 类型的值隐式强制转换为不相关的 flash.text:TextField 类型。

  1. Scene 1, Layer 'Layer 2', Frame 1, Line 8场景 1,第 2 层,第 1 帧,第 8 行

1180: Call to a possibly undefined method on. 1180:调用可能未定义的方法。

  1. Scene 1, Layer 'Layer 2', Frame 1, Line 8场景 1,第 2 层,第 1 帧,第 8 行

1120: Access of undefined property release. 1120:访问未定义的财产授权。

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 . AS2AS3非常不同。 AS3 works by using methods (in the same way as Java , for example). AS3通过使用方法来工作(例如,与Java方式相同)。 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.它的工作原理是将Click EventListener附加到您的计算按钮,该按钮在触发时会运行calculateBMI方法。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM