1

I have an array of items which I would like to be displayed within a dynamic textfield to form a high score list. The amount of items within the arraylist with vary depending on how many high scores are added to it. It is created as standard like this:

var lvl1ScoreArray:Array = new Array();

And items are added to it within the following code:

if (currentLevel == 1)
{
    lvl1highScores.push({score:int(vinylCollected) , player:String(highScoreInput.text)});
    lvl1highScores.sortOn("score", Array.DESCENDING | Array.NUMERIC);
}

I can obviously trace all the items in the array as follows:

for (var i:int = 0; i < lvl1highScores.length; i++)
{
    trace(lvl1highScores[i].score, lvl1highScores[i].player);
}

But I would like to do this within a dynamic textfield called highScoreTxt.. Any suggestions?

1 Answer 1

1

That is simple, just create a movie clip with a text field in it with an instance name of txt. Name the movie clip HighScoreTF and set its linkage to HighScoreTF Then your for loop will looking something like so

for (var i:int = 0; i < lvl1highScores.length; i++)
{
    var tf:HighScoreTF = new HighScoreTF();
    tf.txt.text = lvl1highScores[i].score + " - " + lvl1highScores[i].player;
    tf.y = i * tf.height; //-- you can replace tf.height with a number to adjust spacing
    addChild(tf);
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the quick response Ronnie, I have tried your answer, but am now getting the following errors 1046: Type was not found or was not a compile-time constant: HighScoreTF. 1180: Call to a possibly undefined method HighScoreTF. These are both on the line 'var tf:HighScoreTF = new HighScoreTF();' Any idea why this has happened?
Yes..because you haven't set the linkage to HighScoreTF on the movie clip I told you to create. Its just a movie clip with a text field in it. You HAVE to set the linkage though
Oh right okay, do you reckon you could explain setting linkage to me? Not sure what this is!
Oh, sure. If you've already create the movie clip, locate it in your library panel. Right-click and hit properties. Check the box that says Export for ActionScript and where it says Class enter HighScoreTF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.