Flash multiline textfield autosize script

#1
Dears,
I know that here is few examples how to change the size of text if the length is out of array. For example this:

Code: Select all

private static function ScaleDownTextFieldRight(Input:String, Field:TextField):void
      {
         var wi:int = Field.width;
         var xcoord: int = Field.x;
         Field.autoSize = TextFieldAutoSize.RIGHT;
         Field.text = Input;
         if (wi < Field.width)
         {
            Field.scaleX = wi / Field.width;
            Field.x = xcoord;
         }
      }
My problem is, i need to have a multiline textfield with fixed width and height. In case that the text will be longer, the size of text will automatically changed to more smaller. I am trying to solve this few days but without success.
Do you have any idea please? All examples which i found here are about "one line" text fields.

Thank you very much guys,
Best Regards,
Vojsooo
https://youtu.be/s7rj9TJpFvw - Our system integration in CzechTV Brno
Broadcast technology, on-air graphics systems, SQL databases, visual basic, C#
Expert in Grassvalley products: K2, Stratus
LAWO VSM
Orad: Morpho3D, 3DPlay
Avid: Avid MC

Re: Flash multiline textfield autosize script

#3
Above link works. I have made a template with it. And it works.
as3 code is below. Modify the number of lines required only.

Code: Select all

package 
{
	import flash.text.TextFormat;
	import se.svt.caspar.template.CasparTemplate;
	public class test extends CasparTemplate
	{
		var format:TextFormat = new TextFormat();
		public function test()
		{
		}
		function updateFormat(size:int):void
		{
			format.size = size;
			f0.setTextFormat( format );
		}
		override public function SetData(xmlData:XML):void
		{
			super.SetData(xmlData);
			for each (var element:XML in xmlData.elements())
			{
				if (element. @ id == "f0")
				{
					var smallLimit:int = 5;
					var testSize  = f0.getTextFormat().size;
					while ( testSize > smallLimit )
					{
						updateFormat( testSize );
						trace( f0.numLines  );

						if (f0.numLines > 4)
						{
							testSize--;
						}
						else
						{
							testSize = smallLimit;
						}
					}
				}
			}
		}
	}
}
Attachments
test.zip
(161.69 KiB) Downloaded 55 times