Study Guides (390,000)
CA (150,000)
SFU (5,000)
IAT (80)
IAT 167 (20)
Final

IAT167-ScoreboardExample.docx


Department
Interactive Arts & Tech
Course Code
IAT 167
Professor
Jack Stockholm
Study Guide
Final

This preview shows page 1. to view the full 4 pages of the document.
Main.as
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends Sprite
{
public var scoreboard:Scoreboard = new Scoreboard();
public var clicks:int = 0;
public var lives:int = 10;
public function Main():void
{
addChild(scoreboard);
stage.addEventListener(MouseEvent.CLICK, onMouseClick);
addEventListener(CustomEventScoreboardUpdate.SCOREBOARD_UPDATE,
scoreboardUpadate);
}
public function onMouseClick(event:Event):void
{
clicks++;
var newcustomEvent:CustomEventScoreboardUpdate = new
CustomEventScoreboardUpdate(CustomEventScoreboardUpdate.
SCOREBOARD_UPDATE, Scoreboard.SCOREBOARD_SCORE, clicks.toString(),
true);
dispatchEvent(newcustomEvent);
if (clicks >= 5)
{
clicks = 0;
lives --;
dispatchEvent(new CustomEventScoreboardUpdate
(CustomEventScoreboardUpdate.SCOREBOARD_UPDATE,
Scoreboard.SCOREBOARD_LIVES, lives.toString(), true));
}
}
public function scoreboardUpadate(event:CustomEventScoreboardUpdate):void
{
scoreboard.updateText(event.element, event.value);
}
}
}
You're Reading a Preview

Unlock to view full version