cmpaccione
02-09-2011, 04:20 AM
This is my first week in ActionScript and it shouldn't be this hard!!
Anyway...I think I have the code right but for the life of me I can't figure out how to get the value of a function into a textfield on the stage.
Basically, I have three textfields that have been placed on the stage dynamically. Two are input fields that except a number value and the two values are calculated with a function. I want the result of that calculation to show up in the third text field.
This is how I started my code:
package com.paccione{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFieldType;
public class Main extends MovieClip{
public function Main(){
var origWeight:Number;
var endWeight:Number;
Each text field is set up like this...I won't list them all for the sake of redundancy:
var inputStartWeight:TextField = new TextField();
this.addChild(inputStartWeight);
inputStartWeight.type = TextFieldType.INPUT;
inputStartWeight.width = 100;
inputStartWeight.height = 20;
inputStartWeight.x = 350;
inputStartWeight.y = 100;
inputStartWeight.border = true;
My function to calculate the two input fields:
public function calculation(origWeight:Number,endWeight:Number):Nu mber {
var percentage:Number = (origWeight / endWeight) * 100;
return(percentage);
}
I hope what I'm asking makes sense...it seems simple enough but for some reason I can't figure it out. And please noob it down for me...like I said, it's my first week in my ActionScript class and I have to be using very basic commands.
Thanks in advance!
Anyway...I think I have the code right but for the life of me I can't figure out how to get the value of a function into a textfield on the stage.
Basically, I have three textfields that have been placed on the stage dynamically. Two are input fields that except a number value and the two values are calculated with a function. I want the result of that calculation to show up in the third text field.
This is how I started my code:
package com.paccione{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFieldType;
public class Main extends MovieClip{
public function Main(){
var origWeight:Number;
var endWeight:Number;
Each text field is set up like this...I won't list them all for the sake of redundancy:
var inputStartWeight:TextField = new TextField();
this.addChild(inputStartWeight);
inputStartWeight.type = TextFieldType.INPUT;
inputStartWeight.width = 100;
inputStartWeight.height = 20;
inputStartWeight.x = 350;
inputStartWeight.y = 100;
inputStartWeight.border = true;
My function to calculate the two input fields:
public function calculation(origWeight:Number,endWeight:Number):Nu mber {
var percentage:Number = (origWeight / endWeight) * 100;
return(percentage);
}
I hope what I'm asking makes sense...it seems simple enough but for some reason I can't figure it out. And please noob it down for me...like I said, it's my first week in my ActionScript class and I have to be using very basic commands.
Thanks in advance!