Friday, May 2, 2008

Flash Tip: How to create a Score Counter

Student Asks:

I need to know how to get a score counter to go up when my rabbit collects a carrot.

Developer Response:

Setup a variable outside of any function so that all scripts can access it.

var scoreAmt:Number;

Create a dynamic text field in the stage and give it a name(score).

Add to or subtract from scoreAmt.

scoreAmt += 5; //adds 5
scoreAmt -=5; //subtracts 5

Set the text to the variable.

score = scoreAmt;

Note:There are two ways to set a value to a text field. The tutorial shows the old way of using the var in the Properties box. The new way is to name the text field through the Instance box. In that case you will set it's contents like this. You only need to use one method.

score.text = scoreAmt.

Can any one add to this?

No comments: