473,378 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Multiplication of 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



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();
Feb 27 '08 #1
2 5163
nomad
664 Expert 512MB
here is an example:
I assuming you have 3 input text boxes and one Dynamtic text box and you gave them Variable names. I will use
Expand|Select|Wrap|Line Numbers
  1. number_one 
  2. number_two 
  3. number_three
  4. result_sum 

Limit the textboxes to numbers only. To do this, just select a textbox and click the Character… button in the Properties panel. This will bring up the Character Options box. From there, select “Only”, “Numerals (0-9)”, and click Done.

Now, we need to add our button used to execute our calculations. In the Component panel, select Flash UI Components.
Drag and drop the PushButton component into the scene

Select the PushButton component you’ve just dragged into your scene. In the Properties panel, label the component “Calculate” and set the Click Handler to “onCalculate”. This is the button we will use to calculate the user’s data.


As a final measure, I have given the “Number 1” and “Number 2” textboxes a value of zero.

it’s time to put in the code that will make this movie work.

Add a new layer to the movie, and call it “actions”.

Select the first frame of the “actions” layer. In the Actions panel, add the following code:

Expand|Select|Wrap|Line Numbers
  1. function onCalculate() { 
  2.  one = Number(number_one); 
  3.  two = Number(number_two);
  4.  three =  Number(number_three);
  5.  result_sum = (one * two) + three; 
  6.  
  7. }
This is the code that will make this movie do its magic! Let’s look at what this code does and why.

Expand|Select|Wrap|Line Numbers
  1. function onCalculate() {
This first line starts a new function in the movie. Remember we gave PushButton component a Click Handler of “onCalculate”. When this button is clicked, it will execute the code within this function.

Expand|Select|Wrap|Line Numbers
  1. one = Number(number_one); 
  2. two = Number(number_two);
  3. three =  Number(number_three);
This code has two purposes. The first is to give shorter variable names to the data that’s being calculated. Instead of spelling out “number_one” throughout our code, we can now just use “one”.

We do this to treat these variables as numbers. This is done with Number(), which tells Flash that we to treat values in parentheses as numbers. If we don’t, when we calculate 1 plus 1, we’ll get 11. Or, if we calculate 1 plus 2, we’ll get 12. Instead, with the Number(), when we calculate 1 plus 1, we’ll get 2.

Expand|Select|Wrap|Line Numbers
  1. result_sum = (one * two) + three; 
}

Remember the variable names we gave the textboxe at the bottom? This code puts our calculation results within that textbox. When this code is executed, the “result_sum” textbox will display the result of mutipling Number 1 and Number 2, then adds Number 3. The “result_product” textbox will display the result .

That’s it! Publish your movie, type in some numbers in first two textboxes, and hit Calculate.

nomad.
PS I hope this works I really did not test it.
Feb 27 '08 #2
Hey, nomad, it's you here again!

Thank you, Mr. Professor for this full explanation of the whys it is working or not.
It should take a lot of time to respond so completely...
After reading your post, I feel a little more "intelligent" and younger !
:-)

Oh, by the way: IT WORKS !!!

Have a very nice Thursday.
Best regards,

Gerry
Feb 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Michael Bader | last post by:
Hi, I'm currently working on a matrix multiplication code (matrix times matrix), and have come along some interesting/confusing results concerning the running time of the (apparently) same...
7
by: Jan Bernatik | last post by:
Hi I have a function called from another one, which runs in loop, so that is it called very often something like this: void my_function(int x) { int temp; temp = x * some_const;
9
by: Ralf Hildebrandt | last post by:
Hi all! First of all: I am a C-newbie. I have noticed a "strange" behavior with the standart integer multiplication. The code is: void main(void)
17
by: Christopher Dyken | last post by:
Hi group, I'm trying to implement two routines to handle 32x32-bits and 64x64-bits signed integer multiplication on a 32 bits machine in C. It easy to find descriptions of non-signed...
7
by: VijaKhara | last post by:
Hi all, Is there any method which can implememt the matrix multiplication faster than using the formula as we often do by hand? I am writing the following code and my matrice: one is 3x40000 and...
5
by: Pablo Torres | last post by:
Hi guys! I am working on Conway's Game of Life right now and I've run into a little problem. I represent dead cells with 0s and live ones with 1s. Check this out: , , ] , , ] Now, that's...
4
by: KenNeal | last post by:
Hi, I'm trying to multiply two numbers together within VB and am getting the incorrect result My code has the following.... .... dblDirectRes = dblDirect * dblMultDirect .... All variables...
1
by: Sozos | last post by:
Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help. #define index(i,j,power) (((i)<<(power))+(j)) void...
8
by: kfindley | last post by:
I've been looking online but am having trouble finding sources on using C for basic multiplication. I'm assuming this is not the original purpose of C, but its what I need to do. If anyone can see...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.