ActionScript 3: dynamic text support: score for the game

I am very new to script 3 in action and now I am trying to make a very basic game. However, no matter how many pages I look at, I cannot find a working way to get my game to keep score: /.

What I'm trying to do is make sure that 10 points are added every 10 seconds (now I replace it with a key to see if I can make it work, but he didn’t do it, t). This is the code I'm trying to use right now:

var playerScore:int = 0 stage.addEventListener(MouseEvent.CLICK,onclick); function updateTextFields():void{ playerScoreText.text = ("Player Score: " + playerScore); } if(Key.isDown(Key.G)){ playerScore++; //increase playerScore by 1 updateTextFields(); } 

playerScoreText is the name of the dynamic text any help would be greatly appreciated :)

This code has been added to the timeline.

I think the problem is most likely related to the creation of dynamic text, but I'm not sure.

+6
source share
2 answers

Make sure that the fonts are installed correctly and that the color of the dynamic text field does not match the background color.

also instead of writing

 playerScoreText.text = ("Player Score: " + playerScore); 

try it

 playerScoreText.text = "Player Score: " + String(playerScore); 
+2
source

It looks like you want to do something similar with a timer class. Your key code is not spelled correctly.

 var playerScore:int = 0; var score_timer:Timer = new Timer(10000,0); score_timer.addEventListener(TimerEvent.TIMER,updateTextFields); score_timer.start(); function updateTextFields(e:TimerEvent):void { playerScore+=10 playerScoreText.text = ("Player Score: " + playerScore); } 
+2
source

All Articles