Skip to main content
Pouradam
Inspiring
June 22, 2013
Answered

Change the "Font size" in a TLF Textfield with actionscript?

  • June 22, 2013
  • 1 reply
  • 3308 views

I could not realize how should I resize my TLF Textfiels in flash cs6 with actionscript??

None of these worked:

if (....)

{

     myTLFText.textSize++;

     myTLFText.fontSize++;

}

Error: Access of possibly undefined property size through a reference with static type fl.text:TLFTextField.

I appreciate your kind help please??

This topic has been closed for replies.
Correct answer kglad

Here is the part of code I am using to resize the textfield (and other elements).

/******SET POSITION**********/
function setPosition():void
{
      //Position appBG
      appBG.height = stage.stageHeight;
      appBG.width = appBG.height;

      //Fit the appTXT in middle of screen  (AppTXT is a MovieClip contains sourceText - RTLTextField)
      appTXT.sourceText.width = stage.stageWidth * 0.9;
      appTXT.sourceText.x = stage.stageWidth * 0.05;
      appTXT.sourceText.y = stage.stageHeight * 0.1;

    

      //Fit the maskText layer on top of text;
      maskText.width = appTXT.sourceText.width;
      maskText.height = stage.stageHeight * 0.8;
      maskText.x = stage.stageWidth * 0.05;
      maskText.y = stage.stageHeight * 0.1;

    

      //Set buttons in their proper position

      ...

      if (stage.stageWidth > stage.stageHeight)
      {
            appBG.width = stage.stageWidth;
            appBG.height = appBG.width;
      }

      appBG.x = stage.stageWidth / 2;
      appBG.y = stage.stageHeight / 2;
}

Everything works fine, but when I install the apk on my Google nexus (800x1280), the font size looks VERY SMALL and I can hardly read it!

If I increase the Font size pt (Red Arrow in above PrntScr) to 40. then it reads perfect on phones with 800x1280 screen size. Ok?  But then any OTHER smaller screen cell phones will see the font TOO BIG!

So I need to set the Font size pt by CODE based on a percent of stageWidth to could solve this. thx.


setting width/height is no help.  use scaleX and scaleY like i suggested.

1 reply

kglad
Community Expert
Community Expert
June 22, 2013

you can control the font size using a textformat instance and applying the textformat instance to your textfield:

var tfor:TextFormat=new TextFormat();

var i:int = 1;

while(myTLText.width<300)

{

tfor.size=i;

     myTLFText.setTextFormat(tfor);

i++;

}

Pouradam
PouradamAuthor
Inspiring
June 22, 2013

Thanks a lot for your kind reply. Now I can change the Font size.

but still the bigger problem is my text contains many different text formats
(some words are BOLD, some parts are RED, some words have different Fonts!.) and all are gathered in a TLF Text field called "myTLFText".

When I apply a new Font size, for example:

var tfor:TextFormat=new TextFormat();

tfor.size = 30;

myTLFText.setTextFormat(tfor);

Then all the previous formats are lost! Default Font, Color and Font size of 30 will be applied.

In Microsoft word, when you sellect a paragraph and press " Crtl + ] " or " Ctrl + [ ", it keeps all the Fonts, colors, Bold, Italic, etc. in your selection, and increase or decrease only the Font size all together!

Is this also possible in Flash TLF Text Fields or I'm expecting a lot from Flash??

kglad
Community Expert
Community Expert
June 22, 2013

try:

while(myTLFText.width<300){

myTLFText.scaleX+=.1;

myTLFText.scaleY+=.1;

}