It is currently 22 Jun 2017, 15:20



Flash multiline textfield autosize script

CasparCG Server, Client and development

Moderators: Macey, Jonas Hummelstrand, didikunz

Flash multiline textfield autosize script

Postby Vojsooo » 30 Apr 2017, 19:31

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
User avatar
Vojsooo
 
Posts: 62
Joined: 09 Jun 2014, 16:47
Location: Slovakia, Bratislava

Re: Flash multiline textfield autosize script

Postby dangb » 03 May 2017, 13:33

Hi Vojsooo,

This stackoverflow thread might be helpful?

http://stackoverflow.com/questions/6439687/auto-resize-dynamic-text-font-as3

Cheers

Dan
dangb
 
Posts: 27
Joined: 11 Jul 2016, 21:42

Re: Flash multiline textfield autosize script

Postby vimlesh1975 » 04 May 2017, 18:38

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 34 times
User avatar
vimlesh1975
 
Posts: 602
Joined: 29 Aug 2011, 11:42
Location: Doordarshan, Mumbai, India


Return to Tech and Development

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot], Yahoo [Bot] and 4 guests