IAT167-ScoreboardExample.docx

53 views4 pages

For unlimited access to Study Guides, a Grade+ subscription is required.

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);
}
}
}
Unlock document

This preview shows page 1 of the document.
Unlock all 4 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$10 USD/m
Billed $120 USD annually
Homework Help
Class Notes
Textbook Notes
40 Verified Answers
Study Guides
1 Booster Class