Hit Test

Each time a star flies through the air we want to call either hitPaddle or missPaddle in the main movie. When the star starts we set caught to false. If we catch it as it is falling (not when it is going up) we call hitPaddle and call MovieClip(root).hitPaddle() and set caught to true. When the star starts over (in init()) if he hasn''t been caught we call MovieClip(root).missPaddle();

Modify the code for the FallingStar as follows:

  1. Add a variable caught: var caught:Boolean=false;
  2. Add code in moveit to detect if the star hit the paddle:
  3.   if(this.hitTestObject(MovieClip(root).paddle) && dy>0) {
         MovieClip(root).hitPaddle(); //call function in main movie
  4. Add code in init() to call missPaddle if the star was not caught:
  5.   if(!caught) MovieClip(root).missPaddle();
      caught=false; //reset caught for next round
Get Adobe Flash player
Download the class.

NEXT: Add code to move the paddle