Posted By

sebastianassaf on 08/15/08


Tagged

math as3


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

THEPWN3R


Lynda.com - Using the math class


 / Published in: ActionScript 3
 

URL: http://movielibrary.lynda.com/html/modPage.asp?ID=423

maths functions in actionscript

  1. //simple calculations
  2. trace(2+4);
  3. trace(2-4);
  4. trace(2*4);
  5. trace(2/4);
  6.  
  7. //generate random number
  8. trace(Math.random();
  9. trace(Math.random( * 10); // for numbers bigger than 1
  10.  
  11. // rounding number techniques
  12. die1_mc.gotoAndStop(Math.round(Math.random() * 6)); // round
  13. die1_mc.gotoAndStop(Math.floor(Math.random() * 6)); // round down
  14. die1_mc.gotoAndStop(Math.ceil(Math.random() * 6));// round up
  15.  
  16. // random dice movie function
  17. random_mc.addEventListener(MouseEvent.CLICK; onClick);
  18.  
  19. function onClick(event:MouseEvent):void
  20. {
  21. die1_mc.gotoAndStop(Math.ceil(Math.random() * 6));
  22. }

Report this snippet  

You need to login to post a comment.