PDA

View Full Version : createTextField formatting question


BenWorbs
08-21-2007, 11:16 AM
Hello,

I've created a little count up anumation to be added to a banner I'm working on but can't get the numbers to format in teh way i would like

Here is my script

var count:Number = 22.457;
var maxNum:Number = 26.457;
var num:Number = .45;

this.createTextField("txt",0,0,0,100,50);
txt.multiline = false;
txt.font = "Bliss Medium";
txt.size = 10;

onEnterFrame = function () {
count += num;
if (count>=maxNum) {
num = 0;
txt.text = "26.457";
} else {
txt.text = count/(maxNum/26.457);
}
};

Could someone possibly tell me where I'm going wrong please?

Thankyou in advance

Ben

Noct
08-21-2007, 02:17 PM
Welcome aboard,

Apply font and size changes to a textFormat object, and then apply that format to your field after the text has been added:
var count:Number = 22.457;
var maxNum:Number = 26.457;
var num:Number = .45;
this.createTextField("txt", 0, 0, 0, 100, 50);
txt.multiline = false;
myTextFormat = new TextFormat();
myTextFormat.size = 10;
myTextFormat.font = "Arial";
onEnterFrame = function () {
count += num;
if (count>=maxNum) {
num = 0;
txt.text = "26.457";
txt.setTextFormat(myTextFormat);
} else {
txt.text = count/(maxNum/26.457);
txt.setTextFormat(myTextFormat);
}
};

Or you can use "setNewTextFormat", which will apply the changes directly to the field, and change all text in that field permanently to that format:
var count:Number = 22.457;
var maxNum:Number = 26.457;
var num:Number = .45;
this.createTextField("txt", 0, 0, 0, 100, 50);
txt.multiline = false;
myTextFormat = new TextFormat();
myTextFormat.size = 10;
myTextFormat.font = "Arial";
txt.setNewTextFormat(myTextFormat);
onEnterFrame = function () {
count += num;
if (count>=maxNum) {
num = 0;
txt.text = "26.457";
} else {
txt.text = count/(maxNum/26.457);
}
};

BenWorbs
08-22-2007, 09:00 AM
Thankyou very much Noct thats great. I'm new to Actionscript and help like this is what I need. Sure you'll be hearing from me again :) Ben