Design Lab 5: Game Media   [ Monday 6pm - Rm 908]

instructor: Jonah Warren
email: jonah AT feedtank DOT com
url: http://www.playfulsystems.com/teaching/2007/gamemedia


Object Oriented Programming in Flash
(November 5th, 2007)
An Object Oriented Light
[ Download the ZIP v01
 Download the ZIP v02 ]

The following program has the following structure:

package {
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	public class Light extends MovieClip {
	
		var _lightState:Boolean;
	
		public function Light() {
			trace("Light Made!");
			
			this.x = 36.5;
			this.y = 22.5;
			
			this.buttonMode = true;
			this.useHandCursor = true;
		
			_lightState = false;
		
			this.addEventListener(MouseEvent.CLICK, clickHandler);
		}
		
		public function clickHandler(evt:MouseEvent) {
			_lightState = !_lightState;
			
			updateLightState(_lightState);
		}
		
		public function updateLightState(newState:Boolean) {
			if (_lightState) this.gotoAndStop("on");
			else this.gotoAndStop("off");
		}
	
	}
	
}

var light:Light = new Light();
addChild(light);


This program will allow you to turn on and off the light. Exciting!