Here's the objective. I want the font size of a dynamic text box to change according to the number of characters of the input text. The user types in whatever (up to 50 characters long), then hits an update button to see it in the dynamic text box. But since the dynamic text can only be a single line within a defined area with no horizontal scrolling.
Here's the code I'm having a problem with:
Code:
updateBtn.addEventListener(MouseEvent.CLICK, updateIt);
inputText.maxChars = 50;
function updateIt(event:MouseEvent):void{
dynText.text=inputText.text;
var textFormat:TextFormat = new TextFormat();
if(inputText.length < 18){
textFormat.size = 48;
dynText.setStyle("textFormat");
}
else if((inputText.length >= 18) and (inputText.length < 22)){
textFormat.size=40;
dynText.setStyle("textFormat");
}
else if((inputText.length >= 22) and (inputText.length < 27)){
textFormat.size = 30;
dynText.setStyle("textFormat");
}
else if((inputText.length >=27) and (inputText.length < 37)){
textFormat.size = 20;
dynText.setStyle("textFormat");
}
else if(inputText.length >= 37){
textFormat.size = 12;
dynText.setStyle("textFormat");
}
}
I can't seem to figure out the problem...