It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Flash Forum

Multiplying variables...

Moderator: Phate

Multiplying variables...

Postby Germaris on Wed Feb 27, 2008 9:44 pm

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: Select all
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();
Germaris
 
Posts: 2
Joined: Wed Feb 27, 2008 9:34 pm

Postby Solar42693 on Sun Mar 02, 2008 11:13 pm

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: Select all
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.
User avatar
Solar42693
 
Posts: 35
Joined: Tue Jul 11, 2006 12:56 am

Postby Germaris on Sun Mar 02, 2008 11:22 pm

Hi Solar!

Thanks for replying!
Silly of me... You are right!
Good tip.

Best regards,
Gerry
Germaris
 
Posts: 2
Joined: Wed Feb 27, 2008 9:34 pm


Who is online

Users browsing this forum: No registered users and 0 guests