Design Lab 5: Game Media [ Monday 6pm - Rm 908]
instructor: Jonah Warren
email: jonah AT feedtank DOT com
url: http://www.playfulsystems.com/teaching/2006/gamemedia
The following program has the following structure:
class Light {
var isLightOn:Boolean;
function Light() {
isLightOn = false;
}
function turnOff() {
trace("Turning light off.");
isLightOn = false;
}
function turnOn() {
trace("Turning light on.");
isLightOn = true;
}
function printState() {
if (isLightOn) trace("Light is on.");
else trace("Light is off.");
}
}
var light:Light; light = new Light(); light.printState(); light.turnOn(); light.printState(); light.turnOff(); light.printState();
This program will print out the following:
Light is off. Turning light on. Light is on. Turning light off. Light is off.
The following program has the following structure:
class Light extends MovieClip{
var isLightOn:Boolean;
function Light() {
isLightOn = false;
}
function turnOff() {
trace("Turning light off.");
this.gotoAndStop("off");
isLightOn = false;
}
function turnOn() {
trace("Turning light on.");
this.gotoAndStop("on");
isLightOn = true;
}
function printState() {
if (isLightOn) trace("Light is on.");
else trace("Light is off.");
}
function getState():Boolean {
return isLightOn;
}
}
stop();
lightSwitch.onPress = function() {
if (light.getState()) light.turnOff();
else light.turnOn();
}