HOW the function works is not as important as finding a formula that you can plug into Flash. Since this method estimates the square root of a number, by using a loop to refine the calculation, you may get funny results. To see what I mean try entering a "0". (the actual square root of 0 is 0). If you ever find some spare time you can play with this function and raise the number of iterations. You'll will find that a higher number of passes over the code will generate a value which is closer to true value of the square root. Still, for purposes in Flash, it gets close enough!
To reuse this function in your own calculations, simply copy the frame called "sqrt" into your document. You need to set the variable "iterations" in your file as well. Set it to 10 or 15. This is how many times Flash will cycle through the formula
The function ASSUMES you have a variable called "input". The function performs its magic on that variable, then finishes off by creating a variable called "output".
That's it : )
|» Level Advanced|
Rating: 7 Votes: 125
|Flashjunkie is a self-professed obsessive addict of life. Due to the highly artistic nature required of an Art Director for an Ad agency, he took up Flash to add some math to his diet.|
|Download the files used in this tutorial.|
|Download (4 kb)|
|More help? Search our boards for quick answers!|