milkmit
August 11th, 2009, 05:27 PM
I've got a simple function which strips down a textfield to a specific number of lines, and adds "..." at the end, in order to ensure it fits within the textfield of a specific size.
// add caption textfield
var txtCaption:TextField = new TextField();
txtCaption.selectable = false;
txtCaption.mouseEnabled = false;
txtCaption.embedFonts = true;
txtCaption.x = globalSettings.$upperBoxTextFieldStartX;
txtCaption.y = globalSettings.$upperBoxCaptionTextFieldStartY;
txtCaption.width = globalSettings.$upperBoxTextFieldWidth;
txtCaption.height = globalSettings.$upperBoxCaptionTextFieldHeight;
txtCaption.wordWrap = true;
txtCaption.text = FormatText.symbolSweep(loadedData.ENTRY.DATA.A_CAP TION);
txtCaption.setTextFormat(txtFormatCaption); // this is defined above
// make sure it's cut down before adding
if (txtCaption.numLines > 4) {
while (txtCaption.numLines > 4) {
txtCaption.text = txtCaption.text.substr(0, -1); // remove last character one by one until the textfield is 4 lines in length
}
txtCaption.text = txtCaption.text.substr(0, -5); // remove the last 5 characters to make room for the dots
txtCaption.text = txtCaption.text.concat("..."); // add dots
}
addChild(txtCaption);
I've also got another function (in its own class, FormatText.as) which converts the inputted HTML code into a more Flash-friendly unicode (for instance, € becomes \u20AC, which Flash renders properly as the Euro symbol).
public static function symbolSweep(input:String):String {
var r:RegExp = /€/gi;
return input.replace(r, "\u20AC");
}
The problem is that these two things work perfectly fine individually, but don't seem to play right together. When my textfield exceeds the number of lines I'm allowing, it instead shows up empty, both when set to htmlText or just text, whereas it normally clips it just fine if I don't sent it through the symbolSweep.
I realize this is probably a shot in the dark, but does anyone have any clue whatsoever about what might be happening?
// add caption textfield
var txtCaption:TextField = new TextField();
txtCaption.selectable = false;
txtCaption.mouseEnabled = false;
txtCaption.embedFonts = true;
txtCaption.x = globalSettings.$upperBoxTextFieldStartX;
txtCaption.y = globalSettings.$upperBoxCaptionTextFieldStartY;
txtCaption.width = globalSettings.$upperBoxTextFieldWidth;
txtCaption.height = globalSettings.$upperBoxCaptionTextFieldHeight;
txtCaption.wordWrap = true;
txtCaption.text = FormatText.symbolSweep(loadedData.ENTRY.DATA.A_CAP TION);
txtCaption.setTextFormat(txtFormatCaption); // this is defined above
// make sure it's cut down before adding
if (txtCaption.numLines > 4) {
while (txtCaption.numLines > 4) {
txtCaption.text = txtCaption.text.substr(0, -1); // remove last character one by one until the textfield is 4 lines in length
}
txtCaption.text = txtCaption.text.substr(0, -5); // remove the last 5 characters to make room for the dots
txtCaption.text = txtCaption.text.concat("..."); // add dots
}
addChild(txtCaption);
I've also got another function (in its own class, FormatText.as) which converts the inputted HTML code into a more Flash-friendly unicode (for instance, € becomes \u20AC, which Flash renders properly as the Euro symbol).
public static function symbolSweep(input:String):String {
var r:RegExp = /€/gi;
return input.replace(r, "\u20AC");
}
The problem is that these two things work perfectly fine individually, but don't seem to play right together. When my textfield exceeds the number of lines I'm allowing, it instead shows up empty, both when set to htmlText or just text, whereas it normally clips it just fine if I don't sent it through the symbolSweep.
I realize this is probably a shot in the dark, but does anyone have any clue whatsoever about what might be happening?