Code.GeekInterview.com
 
Code Samples Flash
 

Simple Mathematic Operations (Add, Sub, Mul, Div, Mod)


Code ResourceAuthor: lavanyarani  

Difficulty Level: Intermediate

Published: 6th Jan 2010   Read: 5113 times  

Filed in: Flash
Add Comment


 

 

Sponsored Links


 

 

This program shows how to perform simple Mathematic Operations (Add, Sub, Mul, Div, Mod)

 


Sample Code
  1.  
  2. Step-1: Create 3 input fields and name them n1, n2, r1, respectively in the
  3.              properties panel.
  4. Step-2: Create 5 buttons with the texts on them “add”, “sub”, “mul”, “div”                        
  5.              “div”, “mod” respectively.
  6. Step-3: Select the “addbutton and open the action panel and write the  
  7.              following code in the script pane.
  8. on (press) {
  9.         var a:Number;
  10.         var b:Number;
  11.         a=Number(n1.text);
  12.         b=Number(n2.text);
  13.         r1.text=a+b;
  14. }
  15. Step-4: Select the “sub” button and open the action panel and write the  
  16.              following code in the script pane.
  17. on (press)
  18. {
  19.         var a:Number;
  20.         var b:Number;
  21.         a=Number(n1.text);
  22.         b=Number(n2.text);
  23.         r1.text=a-b;
  24. }
  25. Step-5: Select the “mul” button and open the action panel and write the  
  26.              following code in the script pane.
  27. on (press)
  28. {
  29.         var a:Number;
  30.         var b:Number;
  31.         a=Number(n1.text);
  32.         b=Number(n2.text);
  33.         r1.text=a*b;
  34. }
  35. Step-6: Select the “div” button and open the action panel and write the  
  36.              following code in the script pane.
  37. on (press)
  38. {
  39.         var a:Number;
  40.         var b:Number;
  41.         a=Number(n1.text);
  42.         b=Number(n2.text);
  43.         r1.text=a/b;
  44. }
  45. Step-7: Select the “mod” button and open the action panel and write the  
  46.              following code in the script pane.
  47. on (press)
  48. {
  49.         var a:Number;
  50.         var b:Number;
  51.         a=Number(n1.text);
  52.         b=Number(n2.text);
  53.         r1.text=a%b;
  54. }
  55.  
  56. Step-8: press ctrl+enter to test the movie and enter any two numbers in the
  57.     n1 and n2 fields and click any button and the particular operation  
  58.     will be performed and the result will be displayed in the r1 field
  59.  
Copyright GeekInterview.com


Next Article: Generation of Duplicate Image


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Comments

Please post or give additional source code of simple calculator that apply the rule of precedence.tnx...
Comment posted by: Jarules Mendoza on 2011-03-08T03:34:10

Popular Coders

# Coder NameHits
1. lavanyarani35477

Active Coders

# Coder NameCodes
1. lavanyarani13

Refined Tags