Embedding htmlText in your TextArea control

So I’m currently working on my first mxml project at work (I’ve done other stuff but not at work so they were much less involved).

I realized a little in to the project that using the TextArea control can be a bit of a pain the ass at times. Namely, I couldn’t find a way to embed fonts that were loaded into the flash and set in a stylesheet that I set the TextArea to use.
The problem here was that the textArea component only looks for a single font attributed to it in the styleName attribute that cna be set. If it doesn’t see that there’s a font there it sets embedFonts = false.

So liking to have as much control over things as possible, and realizing that not being able to embed my html goodness was not acceptable, I extended the TextArea class and after some finagling managed to discover the best means for fixing this. It appeared that the UITextField within the TextArea was dispatching a textFieldStyleChange event after it did it’s validation. This alowed me to add a listener to the textField and set the embedFonts attribute to whatever I chose. Here is my class:

 import flash.events.Event;
 import mx.controls.TextArea;
 import mx.core.mx_internal;
 use namespace mx_internal;

 public class TextArea extends mx.controls.TextArea
 {
  public var embedFonts:Boolean = false;
  
  public function TextArea()
  {
   super();
   
  }
  private function handleTextFieldStyleChange(event:Event):void
  {
   textField.embedFonts = this.embedFonts;   
  }
  mx_internal override function createTextField(childIndex:int):void
  {
   
   super.createTextField(childIndex);
   textField.addEventListener("textFieldStyleChange", handleTextFieldStyleChange)
  }
 }

Posted

in

,

by

Comments

Leave a Reply