Code in frame 1 layer 1

//whack.fla
//By Andy Harris, Dummies Guide to Game Programming in Flash


init();

function init(){

  for(i = 0; i < 10; i++){  
    _root.attachMovie("target", "target_" + i, 100 + i);
    theTarget = eval("target_" + i);
    theTarget._x = i * (theTarget._width + 5) + 50;
    theTarget._y = 200;
    theTarget.state = "down";
    theTarget.gotoAndStop("down");
    //larger popUpRate makes targets pop up more frequently
    theTarget.popUpRate = .01;
    //larger resetFrames makes targets stay up longer
    theTarget.resetFrames = 12;

    theTarget.onEnterFrame = function(){
      if (this.state == "down"){
        //pop up randomly
        if (Math.random() < this.popUpRate){
          this.state = "up";
          this.gotoAndStop("up");
          this.counter = this.resetFrames;
        } // end "pop up" if
      } else {
        //count down because target is currently up
        this.counter--;
        if (this.counter < 0){
          //go back down
          this.state = "down";
          this.gotoAndStop("down");
          misses++;
        } // end if
      } // end "up or down" if
    } // end enterFrame

    theTarget.onPress = function(){
      if (this.state == "up"){
        this.state = "down";
        this.gotoAndStop("down");
        hits++;
      } // end if
    } // end onRelease
  } // end for loop
} // end init