I am having trouble understanding / solving a problem with dynamic text and resizing it to fit the text field.
I have got a key part of it working in order to stop words hyphenating onto two lines.
while( _nameText.numLines > _numWords ) {
_size -= 0.2;
_format.size = _size;
_nameText.setTextFormat( _format );
}
The problem now is that if the word on the first line is hyphenated but the second word still fits into the second line the text does not resize. As you can see in the image.
I thought I could resolve this by checking to see if the first line matches the first word of the name string and if not then resizing the text until the word would fit into the first line but when I run this the Flash timeout error occurs as the two strings never seem to match.
I have used toLowerCase() on both strings so that isnt the issue.
var _wordsOnFirstLine:int = _nameText.getLineText( 0 ).lastIndexOf( " " );
if( _wordsOnFirstLine == -1 ) {
while( _nameText.getLineText( 0 ).toLowerCase() != _text.split( " " )[ 0 ].toLowerCase() ) {
_size -= 0.2;
_format.size = _size;
_nameText.setTextFormat( _format );
}
}
Any help greatly appreciated.