Boolean values: True or False

In the movie below click the hat or the shoes to move to the next frame.

Get Adobe Flash player

The hat and shoes have several frames each. When we click one of them, we use if/else to determine if we are in the last frame. If so we go back to the first frame, otherwise we go to the next frame. We could have used identical code for the hat and shoes. The variation is for illustration only. The code is shown below:

shoes.stop(); //to keep from looping through all the frames
shoes.buttonMode=true; //show a hand so user knows to click
shoes.addEventListener(MouseEvent.CLICK,changeShoes);

hat.stop();
hat.buttonMode=true;
hat.addEventListener(MouseEvent.CLICK,changeHat);

function changeShoes(e:MouseEvent):void {
  var pos:int=shoes.currentFrame;
  if(pos<shoes.totalFrames)  //not last frame?
  pos=pos+1; //next frame
  else pos=1; //back to first frame
  shoes.gotoAndStop(pos);
}  //changeShoes

function changeHat(e:MouseEvent):void {
  var pos:int=hat.currentFrame;
  if(pos==hat.totalFrames)  //last frame?
  pos=1; //back to first frame
  else pos=pos+1; //next frame
  hat.gotoAndStop(pos);
} //changeHat

Experiment: Download the movie and add a few frames to the flowers and add code to make them "click-able" also. Download the flash file

NEXT: Making Tea using switch