Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Shrink text Width to text box Width

Community Beginner ,
Feb 17, 2022 Feb 17, 2022

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

TOPICS
ActionScript , Code , How to
274
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 17, 2022 Feb 17, 2022

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 );
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 17, 2022 Feb 17, 2022

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 20, 2022 Feb 20, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2022 Feb 20, 2022

Hi.

 

I see.

 

Can you provide a visual example?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 21, 2022 Feb 21, 2022
LATEST

Three main texts are way too big and going to second line.
I'd like to shrink font size when multiline >1

 

ptscrn.pngexpand imageptscrn1.pngexpand image

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines