A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: TextFormat changes with text.length

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    10

    Question TextFormat changes with text.length

    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...

  2. #2
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    What seems to be the problem?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center