ActionScript 3.0 Arithmetic Operators


/ Published in: ActionScript 3
Save to your folder(s)

This snippet is used for the blog post called Arithmetic Operators in Flash and ActionScript 3.0, which can be found at http://www.brettwidmann.com/2010/10/arithmetic-operators-in-flashactionscript-3-0 which is set to publish on November 1, 2010.


Copy this code and paste it in your HTML
  1. /* Each trace function demonstrates the type
  2.   of Arithmetic operators in Flash.
  3.   Commented out trace() functions demonstrate
  4.   an easier to read example while the verbose
  5.   versions represent cleaner formatting in
  6.   the console.*/
  7.  
  8. //Addition
  9. trace("The sum of 15 + 6 is: " + (15 + 6));
  10. //trace(15 + 6);
  11. trace("\n");
  12.  
  13. //Subtraction
  14. trace("The difference of 15 and 6 is: " + (15 - 6) );
  15. //trace(15 - 6);
  16. trace("\n");
  17.  
  18. //Multiplication
  19. trace("The product of 15 and 6 is: " + (15 * 6));
  20. //trace(15 * 6);
  21. trace("\n");
  22.  
  23. //Division
  24. trace("The quotient of 15 and 6 is: " + (15 / 6));
  25. //trace(15 / 6);
  26. trace("\n");
  27.  
  28. //Modulo
  29. trace("The modulus (remainder) of 15 and 6 is: " + (15 % 6));
  30. //trace(15 % 6);
  31. trace("\n");
  32.  
  33. //Order of Operations Example 1
  34. trace("Parentheticals take precedence in Arithmetic!");
  35. trace("(4 * 2) + 6 = " + ((4 * 2) + 6));
  36. //trace((4 * 2) + 6);
  37. trace("\n");
  38.  
  39. //Order of Operations Example 2
  40. trace("(10 + 6) * 3 = " + ((10 + 6) * 3));
  41. trace("\n");
  42.  
  43. //String Concatenation Example
  44. var concatSentence:String = "This is an example of " + "string concatenation.";
  45. trace(concatSentence);

URL: http://www.brettwidmann.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.