Advertisement
terorama

lesson8 AS2

Aug 28th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //------------------------------------------------------------
  2. //                  Frame 1
  3. //------------------------------------------------------------
  4.  
  5. n_balls=0;
  6.  
  7. for (i=0;i<5;i++) {
  8.     _root.attachMovie("flower8","flower"+i,i);
  9.     _root["flower"+i]._x=200+random(200);
  10.     _root["flower"+i]._y=200+random(200);
  11. }
  12. //---------------------------------------
  13. _root.attachMovie("ballcage", "bc_dyn",8);
  14. _root["bc_dyn"]._x=200;
  15. _root["bc_dyn"]._y=100;
  16.  
  17. _root.attachMovie("ballcage", "bc_dyn3",20);
  18. _root["bc_dyn3"]._x=350;
  19. _root["bc_dyn3"]._y=100;
  20.  
  21. //---------------------------------------
  22. _root.createEmptyMovieClip("zbox",1);
  23. _root.createEmptyMovieClip("zbox3",1);
  24.  
  25. /*_root.zbox.attachMovie("ball88","ball_mc",8);
  26. _root.zbox.ball_mc._x=200;
  27. _root.zbox.ball_mc._y=300;*/
  28.  
  29. //---------------------------------------
  30. ball7.prototype= new MovieClip();
  31.  
  32. function ball7 () {
  33.     this._x=random(Stage.width);
  34.     this._y=random(Stage.height);
  35.     this.velX=random(15);
  36.     this.velY=random(15);
  37. }
  38.  
  39. ball7.prototype.onEnterFrame=function() {
  40.    
  41.     this._x+=this.velX;
  42.     this._y+=this.velY;
  43.     //trace(this._name);
  44.    
  45.    
  46.     if ((this._x<this._width/2) ||
  47.         (this._x>Stage.width-this._width/2)) {
  48.         this.velX*=-1;
  49.         this._x+=this.velX;
  50.     }
  51.    
  52.     if ((this._y<this._height/2) ||
  53.         (this._y>Stage.height-this._height/2)) {
  54.         this.velY*=-1;
  55.         this._y+=this.velY;
  56.     }
  57. }
  58.  
  59. Object.registerClass("ball88",ball7);
  60.  
  61. //_root.attachMovie("ball88","ball_mc77",40);
  62.  
  63.  
  64. //------------------------------------------------------------
  65. //                  Ball88 Clip
  66. //------------------------------------------------------------
  67. onClipEvent(load) {
  68.     this.velX=random(15);
  69.     this.velY=random(15);
  70. }
  71.  
  72.  
  73. onClipEvent(enterFrame) {
  74.     this._x+=this.velX;
  75.     this._y+=this.velY;
  76.     //trace(this._name);
  77.    
  78.    
  79.     if ((this._x<this._width/2) ||
  80.         (this._x>Stage.width-this._width/2)) {
  81.         this.velX*=-1;
  82.         this._x+=this.velX;
  83.     }
  84.    
  85.     if ((this._y<this._height/2) ||
  86.         (this._y>Stage.height-this._height/2)) {
  87.         this.velY*=-1;
  88.         this._y+=this.velY;
  89.     }
  90.    
  91. }
  92.  
  93. //------------------------------------------------------------
  94. //                  Red Button click
  95. //------------------------------------------------------------
  96. on (release) {
  97.     n_balls++;
  98.     _root.zbox3.attachMovie("ball88","ball_mc"+n_balls,
  99.                       50+n_balls);
  100. }
  101.  
  102. //------------------------------------------------------------
  103. //                  Flower8 Clip
  104. //------------------------------------------------------------
  105.  
  106. onClipEvent(load) {
  107.     this.velX=random(15);
  108.     this.velY=random(15);
  109. }
  110.  
  111.  
  112. onClipEvent(enterFrame) {
  113.     this._x+=this.velX;
  114.     this._y+=this.velY;
  115.     //trace(this.name);
  116.    
  117.    
  118.     if ((this._x<0) || (this._x>Stage.width)) {
  119.         this.velX*=-1;
  120.         this._x+=this.velX;
  121.     }
  122.    
  123.     if ((this._y<0) || (this._y>Stage.height)) {
  124.         this.velY*=-1;
  125.         this._y+=this.velY;
  126.     }
  127.    
  128. }
  129.  
  130. //------------------------------------------------------------
  131. //                  BallCage Frame 1
  132. //------------------------------------------------------------
  133. inball_mc.velX=random(5);
  134. inball_mc.velY=random(5);
  135. inball_mc.parH=125;//this._height;
  136. inball_mc.parW=125;//this._width;
  137. inball_mc.par=this;
  138.  
  139.  
  140. ball_xt=0;
  141. //------------------------------------------
  142. inball_mc.onEnterFrame= function () {
  143.     this._x+=this.velX;
  144.     this._y+=this.velY;
  145.     //trace(this.parz._width);
  146.     ball_xt=this._x;
  147.     ball_yt=this._y;
  148.    
  149.    
  150.     if ((this._x<this._width/2-10) ||
  151.         (this._x>this.parW-this._width/2)) {
  152.         this.velX*=-1;
  153.         this._x+=this.velX;
  154.     }
  155.    
  156.     if ((this._y<this._height/2-10) ||
  157.         (this._y>this.parH-this._height/2)) {
  158.         this.velY*=-1;
  159.         this._y+=this.velY;
  160.     }
  161. }
  162. //------------------------------------------
  163. inball_mc.onMouseDown=function() {
  164.    //trace(this.par);
  165.    //this.par.removeMovieClip();
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement