keyboardlogi
keyboardlogi

Reputation: 33

Displaying more text with one Text Input

Is it possible to display more than one text with TextField like so:

Susan            50
Bob              100
Michael          30

This is meant for leaderboard

Regards

Upvotes: 0

Views: 51

Answers (1)

Vesper
Vesper

Reputation: 18747

I'd say for such a leaderboard you need two TextFields one adjacent to another, with identical defaultTextFormat properties, both set with multiline=true; wordwrap=false, and fill left one with names, and right one with scores. This way you can avoid the need of uniform-width fonts. An example:

public class Leaderboard extends Sprite {
    var namesTF:TextField;
    var scoresTF:TextField;
    var dtf:TextFormat;
    ...
        // this goes into the constructor
        dtf=new TextFormat(...);
        namesTF.defaultTextFormat=dtf;
        scoresTF.defaultTextFormat=dtf;
    ...
    public function displayScores(scores:Array):void {
        // scores are objects like {name:Susan,score=200}
        scores.sortOn("score",Array.NUMERIC+Array.DESCENDING);
        namesTF.text='';
        scores.text='';
        for each (var o:Object in scores) {
            namesTF.appendText(o.name+'\n');
            scoresTF.appendText(o.score.toString()+'\n');
        }
    }
}

Adjust the interface to the means your scores are recorded.

Upvotes: 1

Related Questions