ActionScript 3: dynamic text help: scoring for game

actionscript-3dynamicflashtext;

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

What I am trying to do is make it so that every 10 seconds, 10 points is added to the score (right now I have it replaces with a key, to see if I could get that to work, but it didn't).
This is the code I am 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 will be greatly appreciated 🙂

This code was all added in Timeline

I am thinking the problem is most likely something with the creation of the dynamic text, but I am not sure.

Best Answer

Make sure the fonts are embedded properly and that the color of the dynamic text field is not same as the background.

also instead of writing

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

try this

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