Accomplishing this task was a challenge.
Background
TextField -> InteractiveObject -> DisplayObject -> EventDispatcher -> ObjectSo, I set the rotation and the text disappeared. After a couple of hours experimenting, I gave up and searched the web. After another hour, I found this
the text disappearing isn’t a bug – there’s a big warning in the documentation at the top of the class file – Flash won’t render any TextField that’s rotated UNLESS you embed the fonts.Good information ... but it is NOT in the Flash AS3 help file. I eventually found
You can rotate text that uses embedded fontsin Advanced text rendering by searching the help for embed fonts. Until I figured out the details (given below) and was actually able to rotate text, the following 2 help topics were just confusing.
Using Embedded Fonts
This is a code example
protected var FLabel : TextField; public function Configure_Label():void{ var format: TextFormat = new TextFormat(); var a : Array = Font.enumerateFonts(false); if (a.length > 0){ format.font = a[0]["fontName"];// required to rotate text } else { trace("***** There are no embedded fonts *****"); } format.size = 14; FLabel = new TextField; FLabel.defaultTextFormat = format; // must be before setting the text FLabel.embedFonts = true; // required to rotate text FLabel.autoSize = TextFieldAutoSize.CENTER; // affects horizontal location FLabel.wordWrap = false; FSprite.addChild(FLabel); // FSprite is set elsewhere, this line displays the label } // This is how the text is modified after the label is defined FLabel = "Microns - um"; // Do NOT include any characters that are NOT embedded |
Note - Without embedded fonts, some rotated text will display when running from the Flash IDE but not from the web. Personally, I prefer to know that there is a problem ... BEFORE ... deploying an application.
In an AS file, these might be needed
import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFieldType; |
Rotating Text
public override function displayLabel():void{ // rotate and center label FLabel.rotation = -90; // rotate first so height and width are correct FLabel.x = -40; FLabel.y = (FAvailable_Space + FLabel.height)/2; // center text } |
An embedded font must be attached and enabled BEFORE setting rotation.
When first testing this, I created a text field and rotated it at design time using the Free Transform Tool ... and it displayed without embedding any fonts. This appears to be because
It took several hours of experimenting before I decided that this was a Flash design problem. After another hour or so, I found the hint on the web about embedding fonts.
I tried embedding fonts with one field and the text displayed rotated. The *.swf file size changed from 3 kb to 5 kb (27 kb to 38 kb in a second test case). BUT ... only the one field was rendered. None of the other rotated text fields I was experimenting with were displayed until I also embedded fonts for them.
When you manually place text on the form (via the ToolBar), and make it Dynamic, the option to embed text is provided in the Properties frame. Also note that you MUST select Anti-alias for .., otherwise, some of the text will just disappear. (I use Anti-alias for animation, in my opinion, it is not as fuzzy as Anti-alias for readability.) In addition, you should not change the font size in code if Bitmap Text is selected ... the text will look terrible
When changing the ComboBox next to the Embed... button, there is a pop-up that says
The rendering method you selected requires embedded characters. Click Embed to specify the characters to embed in the SWF.Not real help since it does not appear unless you modify the value from Use device fonts (not the default) to something else.
Failure Using Embedded Fonts
var a : Array = Font.enumerateFonts(false); |
I was able to trace this to a specific Static Text field.
There is no way to describe this type of design problem harshly enough.
Adding Static Text to a form should NEVER cause a program to fail ... ever ... using any known programming language.
Of course, I tried to create a simple test case to demonstrate this problem ... but it refused to fail. Instead, to document this problem, I started with a failing project and removed everything except 2 text fields and 2 lines of code. I even deleted all the library entries. I have included the following in Embed_Design_Problem.zip
Simple - fails.fla | 614 kb |
Will not fail - but should.fla | 483 kb |
var a : Array = Font.enumerateFonts(false); trace("Length of array", a.length, "(should be one, 0 means failure)"); |