Instead of the standard use of recursive functions (where a function calls itself over and over) this one simply loops until it reaches one and multiplies it to the total. Here's the basic source code:
If ( n <%gt%> 0) Set Variable: "i" = 1 Set Variable: "total" = n Loop While (i<%lt%>n) Set Variable: "total" = total*(n-i) Set Variable: "i" = i+1 End Loop Else If (n=0) Set Variable: "total" = 1 End If If (n<%lt%>0) Set Variable: "total" = "Negative Num" End If
It first checks to see if n (the input number) is positive then it just decreases the number to be multiplied. If it's zero then the answer is automatically 1. It prints an error message.
To use in your own apps, either copy the above script into the appropriate frame or you can check out the button action in my .fla. Good luck and enjoy!
|» Level Intermediate|
Rating: 7 Votes: 78
|No information about the author has been provided.|
|Download the files used in this tutorial.|
|Download (91 kb)|
|More help? Search our boards for quick answers!|