Bouncing_bubbles.fla this is the source code.

  1. //allright people here it goes…          
  2.  
  3. var count = 0;          
  4.  
  5. //this is the variable that increments each time we add a
  6. //new ball on the screen. Moreover we also decrement it every time we remove a ball
  7. //to keep the Array balls coherent otherwise we would get undefined values
  8. //if we decide to remove some of the balls and then add others.          
  9.  
  10. var balls = new Array();        //this is the array that is going to keep the instance names of each ball on the stage var speedx = new Array();// this is the array that will contain the speeds on the X axis          
  11.  
  12. var speedy = new Array();       // speedy = same thing as the speedx -> addBall below function adds movieclips on the stage and also creates instance names for each added ball. All the instance name are in the balls Array;          
  13.  
  14. addBall.onRelease = function () {          
  15.  
  16. balls[count]=_root.attachMovie("Ball", "ball"+count,_root.getNextHighestDepth());          
  17.  
  18.         //the above line places each instance name into the array          
  19.  
  20.  balls[count]._x=20+Math.random()*400// these two lines place the movieclip on the stage at          
  21.  
  22.  balls[count]._y=20+Math.random()*200// the designated coordinates with randomness.          
  23.  
  24. speedx[count] = Math.random() * 8;      //every time a ball is created a speed value is assigned to it on x or y axis        
  25.  
  26.  speedy[count] = Math.random() * 8;     //every time a ball is created a speed value is assigned to it on x or y axis    
  27.  
  28. color = new Color(balls[count]);          
  29.  
  30.  color.setRGB(Math.random()*0xFF0000+0x00FF00+0x0000FF);          
  31.  
  32. trace(balls);   // this traces the array          
  33.  
  34.  trace (count)// display that count value          
  35.  
  36.  speedx[balls.length-1].num = balls.length1;          
  37.  
  38.  speedy[balls.length-1].num = balls.length1;          
  39.  
  40. balls[balls.length-1].num = balls.length1;          
  41.  
  42.  // in the above line we add the .num property equal with count to use it to maintain the array coherent after adding/removing balls          
  43.  
  44.  balls[balls.length-1].onRelease = function(){          
  45.  
  46.  //this part gives each ball the functionality to be clicked and to be removed off the stage.
  47. //Also the names from the array are going to be removed and kept synchronized.          
  48.  
  49.  for (i=this.num+1; i           balls[i].num–;}//this sets the nums of the balls          
  50.  
  51. //in higher elements of the array. This part decrements the .num property to every element to the right
  52. //of the clicked ball in the array. Example [1,2,3,4,5] if we click on 3 and remove it the
  53. // elements to the right of it will have different position tags. so we have to decrement those.          
  54.  
  55. speedx.splice(this.num,1);      //this removes the value from the speedx array          
  56.  
  57.  speedy.splice(this.num,1);     // speedy = the same as for speedx          
  58.  
  59.  balls.splice(this.num,1);      // this line  removes the element from the array          
  60.  
  61.  this.removeMovieClip();                //this line removes the actual movieclip          
  62.  
  63.  trace(speedx)// I am doing a trace here to see if the array is clean          
  64.  
  65. trace(balls);   // traces the array balls          
  66.  
  67.         count–;        //decrements the counter to help keep the array synchronized after          
  68.  
  69. //we removed a ball from the array. because if we then decide to add the empty
  70. //spots in the array will appear as undefined.          
  71.  
  72.         }          
  73.  
  74. trace(count);          
  75.  
  76.  trace(balls);          
  77.  
  78.  trace(balls[count].num);          
  79.  
  80.  speedx[count] = Math.random() * 8;          
  81.  
  82.  speedy[count] = Math.random() * 8;          
  83.  
  84.  realspeedx[count] = speedx[count];          
  85.  
  86.  realspeedy[count] = speedy[count];          
  87.  
  88. count++;// this increments the counter.. don’t be fulled about the count. You would          
  89.  
  90.  //think that it should not be decremented before we increment but this is about the scope.          
  91.  
  92.  // we decrement only when we click to remove a ball.          
  93.  
  94. }          
  95.  
  96. //———————Movement—————-          
  97.  
  98. var bounce = setInterval (movement, 30);// this interval calls the  the movement function by an interval of 30 milliseconds or so          
  99.  
  100. var moving:Boolean = true; // we need this value to test if the balls are moving or not          
  101.  
  102. stopBtn.onRelease = function(){          
  103.  
  104. if (moving) {                           //these four lines test to see if the start of "moving" if it is false or not          
  105.  
  106.  stopBtn._alpha = 0;                    // this guy sets the alpha(transparency to 0 to see the (start button after it moving has changed))          
  107.  
  108.  clearInterval(bounce);         // this stops the interval therefore stopping the moving          
  109.  
  110.  moving = false;                                // this is required because this is the property that about which we know if the balls are moving or not          
  111.  
  112.                                                         // it is also funny because we never actually test somehow to see if the balls change coordinates          
  113.  
  114.                                                         // we just test to seee if "moving" is false or true and then we just start or stop the interval          
  115.  
  116.                                                         //so this test is a work around. (this is a personal view )          
  117.  
  118. }          
  119.  
  120.  else {                                                                 //this is the else statement that set the motion back on          
  121.  
  122.  stopBtn._alpha = 100;                                  // this restores the stopButton back to being opaque          
  123.  
  124.  bounce = setInterval(movement, 30);          
  125.  
  126.  moving = true;          
  127.  
  128. }}          
  129.  
  130. function movement(){ // This function moves all my bubles on the screen. (movement is the function set in the "setInterval" by 30 miliseconds)          
  131.  
  132. for (count = 0; count{          
  133.  
  134.  balls[count]._x+= speedx [count];          
  135.  
  136.  balls[count]._y+= speedy [count];          
  137.  
  138. if (balls[count]._x > 550-balls[count]._width/2 )       {          
  139.  
  140.         speedx[count] = speedx[count]*(-1);          
  141.  
  142.                                                                                                         }          
  143.  
  144.  if (balls[count]._y > 300-balls[count]._width/2 )      {          
  145.  
  146.         speedy[count] = speedy[count]*(-1);          
  147.  
  148.                                                                                                         }          
  149.  
  150.  if (balls[count]._x < (balls[count]._width/2)  )       {          
  151.  
  152.         speedx[count] = speedx[count]*(-1);          
  153.  
  154.                                                                                                         }          
  155.  
  156.  if (balls[count]._y < balls[count]._width/2)           {          
  157.  
  158.         speedy[count] = speedy[count]*(-1);          
  159.  
  160.                                                                                                         }          
  161.  
  162. for (i = 0; iif (balls[i].hitTest(balls[count])) {          
  163.  
  164. color = new Color(balls[count]);          
  165.  
  166. color.setRGB(Math.random()*0xFF0000+0x00FF00+0x0000FF);          
  167.  
  168. color = new Color(balls[i]);          
  169.  
  170. color.setRGB(Math.random()*0xFF0000+0x00FF00+0x0000FF);}          
  171.  
  172. trace(balls[count]._x);          
  173.  
  174. trace(balls[count]._y);          
  175.  
  176. }}