The Spinner Class


Get Adobe Flash player

The definition for a class is in a seperate file. The name of the file is the same as the name of the class with the extension as. The Spinner.as file is shown below:

package {
	import flash.display.MovieClip;
	import flash.events.*;
	public class Spinner extends MovieClip {
		public var speed:int=3; //initial value
		public function Spinner() {
			this.addEventListener(Event.ENTER_FRAME,spin);
		} //constructor
        private function spin(e:Event):void {
	       this.rotation=this.rotation+speed; //rotate itself
		} //spin
	} //class
} //package


Get Adobe Flash player

Open the link to Spinner.as and save it to your computer in the same directoy where you will create the spinning stars movie. Or create it yourself by selecting File, New, ActionScript 3.0 class. You will be prompted for a name. Name it Spinner. When you save it you will be prompted wit the name Spinner.as.


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.

 
 

A Spinner Class