We Recommend

Mastering Regular Expressions Mastering Regular Expressions
As this book shows, a command of regular expressions is an invaluable skill. Regular expressions allow you to code complex and subtle text processing that you never imagined could be automated. Regular expressions can save you time and aggravation. They can be used to craft elegant solutions to a wide range of problems. Once you've mastered regular expressions, they'll become an invaluable part of your toolkit. You will wonder how you ever got by without them.


Posted By

dhjapan on 03/28/08


Tagged

random duplicate


Versions (?)


Stars arround


Published in: ActionScript 


randomly duplicate a movie clip around a square

  1. staring = false;
  2. max_star = 10;
  3. current_star_num = 0;
  4. star_num = 0;
  5. square_w = 400;
  6. square_h = 200;
  7. alea = 40;
  8. this.onEnterFrame = function() {
  9. if(!staring || current_star_num >= max_star) return;
  10. var n_star = Math.round(Math.random()*1)+1;
  11. for(var i=0; i<=n_star; i++) {
  12. star_num++;
  13. current_star_num++;
  14. duplicateMovieClip(star_mc, "star" + star_num, star_num);
  15. var new_star = this["star" + star_num];
  16. // position
  17. new_star._x = Math.random()*(square_w+alea) - (alea/2);
  18. new_star._y = Math.random()*(square_h+alea) - (alea/2);
  19. if(Math.random()*2>0.5) new_star._x = (Math.round(Math.random()*2)%2)*square_w + Math.round(Math.random()*alea) - (alea/2); // horiz
  20. else new_star._y = (Math.round(Math.random()*2)%2)*square_h + Math.round(Math.random()*alea) - (alea/2); // vert
  21. new_star._alpha = 0;
  22. new_star._xscale = new_star._yscale = Math.round(Math.random()*50) + 50;
  23. new_star.speed = Math.round(Math.random()*10+3);
  24. new_star.way = "in";
  25. new_star.onEnterFrame = function () {
  26. if (this.way == "in") {
  27. this._alpha = Math.min(100, this._alpha+this.speed);
  28. speed = speed - Math.max(1,speed*.3);
  29. if(this._alpha == 100) this.way = "out";
  30. } else if (this.way == "out") {
  31. this._alpha = Math.max(0, this._alpha-this.speed);
  32. speed = speed + Math.min(10,speed*1.5);
  33. if(this._alpha == 0){
  34. current_star_num--;
  35. delete this.onEnterFrame;
  36. removeMovieClip(this);
  37. }
  38. }
  39. }
  40.  
  41. }
  42. }

Report this snippet 

You need to login to post a comment.