OOPs: Object Oriented Programming

Get Adobe Flash player
  1. Download the Clicker.as class and save it in your project directory.
  2. Download the ClickerClown project and save it in the same directory.
  3. In the demo movie above several things are click-able, but only the hat and shoes in the file you downloaded.
  4. Add frames to the flowers, pants, and jacket and make them Clickers also.
  5. Study the code for the Clicker class. Make sure you understand what each line does.
The code for the clicker class is shown below:
package {
	import flash.display.MovieClip;
	import flash.events.*;
	public class Clicker extends MovieClip {
		public function Clicker() {
			this.stop(); //prevent it from cycling through all the frames
			this.buttonMode=true; //show a hand
			this.addEventListener(MouseEvent.CLICK, goClick); //listen for the click
		}//constructor
		private function goClick(e:MouseEvent):void {
			if (currentFrame<totalFrames) {  //not at the last frame
				gotoAndStop(currentFrame+1); //go to the next frame
			} else {
				gotoAndStop(1); //go back to the first frame
			}
		}//goClick
	}//class
}//package

NEXT: Add new instance at run time