You store the score as a number in a variable. You convert it to a string in order to display it.
while( scoreDisplay.length < 4 ) nnnn; is a loop which will repeat while the length of the string is less than 4. In this case, the program adds a "0" to the front of the scoreDisplay string. It then checks the length again, adds another "0", etc, until the length is 4.
The way I would use this would be to create a updateScore() function that adds a value to the score and then converts it to a padded string:
var gameScoreField:TextField = new TextField();
var gameScore:uint = 0;
var gameScoreDisplay:String = "0000";
gameScoreField.text = "Score: 0000";
addChild(gameScoreField);
function updateScore( amount:int ):void
{
gameScore += amount;
if( gameScore > 9999 ) gameScore = 9999;
if( gameScore < 0 ) gameScore = 0;
gameScoreDisplay= gameScore.toString();
while( gameScoreDisplay.length < 4 ) gameScoreDisplay = "0" + gameScoreDisplay;
gameScoreField.text = "Score: " + gameScoreDisplay;
}
Then you could call this function whenever you wanted to update the score. Make sense?