Scores

Adding a score to an interactive

The first step is to deciding on a numeric structiure that will give/take points off.

Then we add them as a list of contants at the start of the class:

private
static const pointsForMatch :int = 100
private
static const pointsForMiss :int = -5

The score itself should be stored in a variable declared at the start of the class and set to 0 in the constructor window:

private
var gameScore :int
gameScore
= 0

The score will be displayed in a textfield (create it through code or have it named on the timeline):

private
var gameScoreField : textField
gameScoreField
= new TextField ;
addChild
(gameScoreField) ;


The action of showing the score we place it INSIDE a function, so it can be recalled everytime the score has to change.

public
function showGameScore () {
gameScoreField
.text = "Score:" + String (gameScore) ;
}

When the event that grans/substratcts points takesplace we will add the code to change the score

gameScore += pointsForMatch  
gameScore += pointsForMiss The number in this case will be negative