Question

I want to change the font size of Flash's TextArea component which is currently on the stage using AS3.

I tried linking a TextFormat object to the TextAera by its instance name, but I get this error:

Scene 1, Layer 'actions', Frame 1, Line 44  1061: Call to a possibly undefined method setTextFormat through a reference with static type fl.controls:TextArea.

Here is the AS3 code:

var myTextFormat:TextFormat = new TextFormat();

myTextFormat.font = "Arial";
myTextFormat.size = 10;
myTextFormat.color = 0xffffff;

my_textArea.setTextFormat(myTextFormat)
Was it helpful?

Solution

Try this snippet:

myTextArea.setStyle("textFormat", myTextAreaFormat);

OTHER TIPS

What I discovered is that the textFormat needs to be set prior to adding the text. When you do that, the setTextFormat command works fine. However, if you define the associated textFormat after its associated textField has been defined, it breaks and the font size isn't set.

  1. define a wrapper (in mine, I used a sprite) for the textField
  2. define textFormat for your textBox (in mine I defined "textBoxFormat")
  3. define your text field (in mine, I used "textBox")
  4. add textBox to it's wrapper
  5. Finally, set the textFormat ==> textBox.setTextFormat(textBoxFormat);

add the wrapper from step 1 to the stage (or other element).

To be honest, I'm not 100% sure the first step is required, but I found it beneficial to wrap the textField, just to be safe. 34 years of programming out the door with my introduction to Adobe's weird "standards". Wish there was a practical alternative, but there doesn't seem to be.

Although One answer is accepted, That doesn't work for me and I found this solution:

import mx.controls.TextArea;

_global.styles.TextArea.setStyle("fontFamily", "Arial");

_global.styles.TextArea.setStyle("fontSize", 30);

PS: If you need in AS2 .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top