Shrink text Width to text box Width
Copy link to clipboard
Copied
Hello
Did it lots of times when exporting SWF, but first time doing HTML5 and having hard time.
600px Text field width, when user enter longer text i want font size to shrink.
current (Max) font size 60px, Min font size will decrese up to 20px.
Right now text just go to second line and font are keeping its size.
Thanx
Copy link to clipboard
Copied
BTW, this is the AS for same function but within SWF, Checking if text long enough to second line.
var smallLimit:int = 10;
var format:TextFormat = new TextFormat();
field0.tf.text = "Looks Like this is too long for this text box";
var testSize:int = 90;
while( testSize > smallLimit ){
updateFormat( testSize );
if(field0.tf.numLines > 1 ){
testSize--;
}else{
testSize = smallLimit;
}
}
function updateFormat(size:int):void{
format.size = size;
field0.tf.setTextFormat( format );
}
Copy link to clipboard
Copied
Hi.
How do you intend do grab the user's text?
Because there's no canvas/CreateJS based text input in the HTML5 document.
The possibilites are the text component (Window > Components > User Interface > TextInput) or an HTML text created at runtime.
Please let us know.
Regards,
JC
Copy link to clipboard
Copied
Thanx for your replay.
the HTML is part of TV broadcastng graphic, it takes data from a channel playlist.
It works with text, images, videos and countdown data.
There are graphics which grow the background according to text length, and there are rgaphic with fixed length which font needs to shrink if the text is too long. What i cannot find is how to do the second option.
Copy link to clipboard
Copied
Hi.
I see.
Can you provide a visual example?
Copy link to clipboard
Copied
Three main texts are way too big and going to second line.
I'd like to shrink font size when multiline >1

