Retrieving TextFormat from TextField with Embedded Font
Creating notes for myself to reference when creating flash pages using the Flash CS5 IDE.
This post is going to cover how to retrieve TextFormat settings when I would like to change the text in dynamic text fields on the fly. I typically layout flash pages with TextFields placed in the desired location on the stage. When an interaction has been setup and the values of the text fields needs to change dynamically, I always struggle to remember exactly what I did each time.
Simple approach Part 1:
- Embed the font in the dynamic TextField with desired attributes set in property tab
- TextField paragraph setting set to Justify*
- Programmatically retrieve the TextFields text format properties to be used later
* – this seems to prevent cropping of characters in the text field when values are changed. When I tried to set this attribute programmatically, the text characters would get cropped when I mixed font attributes within a text field vs setting the whole TextField from the stage (so just set this item globally on the stage properties tab view for the designated TextField).
The code below illustrates the retrieval of the TextFormat settings for a TextField named choice_txt:
//store initial text format for choice textField //used when I need to modify text later choiceTextFormat = choice_txt.getTextFormat();
The format setting for the text field can then be reapplied when the text is modified:
//set new movie clip text field value choice_txt.text = "New text to be displayed or appended"; //apply text formatting to maintain current look and feel choice_txt.setTextFormat(choiceTextFormat);
Next in series, Part 2