| View previous topic :: View next topic |
| Author |
Message |
Germaris
Joined: 27 Feb 2008 Posts: 2
|
Posted: Wed Feb 27, 2008 10:44 pm Post subject: Multiplying variables... |
|
|
Hi there!
Here is the whole script of a test document which doesn't work...
Excuse me but I never used multiplication of variables and I confess how shameful I feel.
I absolutely don't understand the explanations the Flash Help contains...
Document contains three Input Fields, a Dynamic Field and a Button.
Clicking the Button returns NaN !!!
I thank you in advance for any help.
Best regards from Old Gerry
| Code: |
var a:Number = new Number(field1.text);
var b:Number = new Number(field2.text);
var c:Number = new Number(field3.text);
operationFct = function () {
var res:Number = new Number();
res = (a * b) + c;
resultFld.text = res;
};
myButton.onRelease = function() {
operationFct();
};
stop(); |
|
|
| Back to top |
|
 |
|
|
Solar42693

Joined: 11 Jul 2006 Posts: 35
|
Posted: Mon Mar 03, 2008 12:13 am Post subject: Re: Multiplying variables... |
|
|
The problem isn't your multiplication. When you defined var a-c, it was when the frame loaded. At that point, there was nothing in them. You need to redefine your variables in the function like this:
| Code: |
operationFct = function () {
var a:Number = new Number(field1.text);
var b:Number = new Number(field2.text);
var c:Number = new Number(field3.text);
var res:Number = new Number();
res = (a*b)+c;
resultFld.text = res;
};
myButton.onRelease = function() {
operationFct();
};
stop();
|
Although if you leave the input textfields empty you would still get NaN. |
|
| Back to top |
|
 |
Germaris
Joined: 27 Feb 2008 Posts: 2
|
Posted: Mon Mar 03, 2008 12:22 am Post subject: Re: Multiplying variables... |
|
|
Hi Solar!
Thanks for replying!
Silly of me... You are right!
Good tip.
Best regards,
Gerry |
|
| Back to top |
|
 |
|