The Clicker Clown


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 clickable, 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 undersatnad 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

INDEX, Spinning Stars: Objects, A Spinner Class, The Spinner Movie: Using a Class, The Clicker Class, Add new instance at run time, Add new instance at run time DEMO, Create a Flasher class
Next lesson: OOPs: More Classes

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

The Clicker Class