开发者

Syntax problem with textfield as3

开发者 https://www.devze.com 2023-02-21 17:03 出处:网络
I have this code gameOver1.text = (count1.currentCount / 100).toString(); but i want to add some text before i display the current count. for instance in gameOver1.text i want to say

I have this code

gameOver1.text = (count1.currentCount / 100).toString();

but i want to add some text before i display the current count. for instance in gameOver1.text i want to say

Score : (and then the count)

开发者_StackOverflow

thanks.


Just use : gameOver1.text = "Score" + (count1.currentCount / 100).toString();

Action script was derived from ECMA script. One of the reasons as to why it's similar to javascript with features like string manipulation. Apart from string concatenation, other examples include:

  • myString.charAt(0);

  • myString.substring(0,4);

  • myString.substring(4);

  • myString.slice(4,9);

  • myString.search("Word");

  • myString.toLowerCase();

  • myString.toUpperCase();

  • myString.length;

  • myString.replace(myString.substring(0,3), "New");


var score:Number = count1.currentCount / 100;
gameOver1.text = "Score:"+score;

You can add strings together with the + operator. When you use Numbers or ints there (or any other type), their toString() function will be called.


You may want

gameOver1.text = "Score: " + int(count1.currentCount/100);

If your score needs to show and integer, with no fractional part. Or possibly:

gameOver1.text = "Score: " + int((count1.currentCount+50)/100);

or

gameOver1.text = "Score: " + Math.round(count1.currentCount/100);

If you want an integer score but want to round rather than truncate to int (same as floor).

gameOver1.text = "Score: " + (count1.currentCount/100).toFixed(2);

If you want to display rounded to some fixed number of decimal places (2 places in the example). You may even require:

gameOver1.text = "Score: " + Math.ceil(count1.currentCount/100);

If you always want to round up.


You can append strings simply by adding them together. So write

gameOver1.text = "Score: " + (count1.currentCount / 100).toString();
0

精彩评论

暂无评论...
验证码 换一张
取 消