Digital Survivors
 

Perform Math Calculations in Flash

Scott Manning
April 30, 2003 | Comments (1)

The days of Flash being used solely for entertainment are over. Macromedia has spent an enormous amount of money and effort to bring Flash out of its 'animation only' box, and promote it as a cross-platform development environment, as well as a designer environment. Along with the funny cartoons, Flash can now be used to build business applications.

One of the basic requirements of any business app is the ability to do math. In this tutorial, we will cover how to do basic arithmetic in Flash. We'll also cover the capture of data input by a user, and learn how to perform calculations based on this data.

Read the full tutorial


Enjoy this article? There's more. Digital Survivors is a source of articles, tutorials, reviews, and commentary on all things digital.

Stay informed with rss, our feed is permanently ad-free.

These articles are new:

bullet Valkyrie
bullet 1940 Aircraft Production Figures
bullet Let Teachers Carry Concealed Firearms at Schools
bullet 50 Books on World War II Recommended by John Keegan

If you don't immediately see what you want, you can start a topic in our forums.

 



Comments (1):
1) Posted by: Sev
May 24, 2006 7:18 AM

I am writing a GUI for the calculations on an excel spreadsheet.

The spreadsheet was originally conceived to allow quick evaluations to be made on the distance from the camera to a specific part - it pertains to a peice of optical measuring equipment used in the motor industry to allow surfaces to be measured. The product is called Ondulo and the maker is a french company called Techlab. http://www.techlab.fr/Surface.htm

I have designed the GUI, and with the help of Scott Manning's great maths calculations article on site point http://www.sitepoint.com/article/math-calculations-flash

I managed to get the fields and the basic calculations to work.

This is now the point where I need help-

The movie only has one frame but many layers. I've kept all of the scripting on a separate layer.

I have two buttons, one labelled calculate, the other - reset. They both were pulled from the UI components box in Flash MX.

There are 18 text boxes, 5 of which are input, the rest dynamic text to show the results.

I would like to round the visible results fields up to the nearest whole number (the remaining results fields are hidden in a layer positioned behind the background graphic), and would like the reset button to clear everything and allow the user to start again.

If I could find out how, i'd upload the .fla for you to examine.

Here is the code for your convenience:

function onCalculate() {
c4 = Number (c4) ;
c5 = Number (c5) ;
c6 = Number (c6) ;
c10 = Number (c10) ;
c11 = Number (c11) ;
c12 = 4*c10/5 ;
c13 = c10/c11 ;
c17 = c6/(1+c13*c5*((c6-c4)/(c4*c4))) ;
c18 = c6/(1-c13*c5*(c6-c4)/(c4*c4)) ;
c19 = c18-c17 ;
c20 = c19/2 ;
c21 = c17*c12/c4 ;
c22 = c18*c12/c4 ;
c23 = c22-c21 ;
c235 = c23/2 ;
c24 = c21/c11 ;
c25 = c22/c11 ;
c26 = c25/c24 ;
}


I hope you can all help to guide me in the right direction... foundation Actionscript on order from amazon as we speak!!

The whole useing flash for math functionality is really poorly documented - loads on how to generate maths related effects, but not alot on real world applications such as engineering and such like.

I know that if I had the AS know how, there would be so many small swf. files that could be written for students, engineers and scientists to use to assist them visually in calculations rather than having to resort to spreadsheets- and the greatest bebefit would be that they would be truly platform indipendent. And lets face it... who doesn't have a flash plug-in installed these days?!


border