Dynamic TextFields with system font
April 29th, 2005 by ThomasWhen creating dynamic TextFields with embedFonts=false - especially when modifying an existing project for not-embeddable charactersets like chinese - and things don't look the way they're supposed to, check the following...
If you need to measure the bounds of the text with textField.textWidth for example because you need to position something next to it, the Textfield shouldn't be nested in a MovieClip that has a scaling!=100%. Flash seems to apply some imaginary inverse-scale to the actual value, i.e. you create a TextField in a MovieClip with _xscale=1 and call textField.textWidth - where the natural textWidth would be 50px - it would return somehting like 6000px!
Try the following:
- var textFormat = new TextFormat("Arial", 12, 0x000000, false, false, false, "", "", "left", 0, 0, 0, 0);
- this.createEmptyMovieClip("scaleMe", 1);
- scaleMe._xscale=1;
- scaleMe._yscale=1;
- scaleMe.createTextField("textField", 1, 0, 0, 10, 10);
- scaleMe.textField.html = true;
- // try that with true, both values will be the same
- scaleMe.textField.embedFonts = false;
- scaleMe.textField.multiline = false;
- scaleMe.textField.selectable = true;
- scaleMe.textField.htmlText="Measure me";
- scaleMe.textField.setTextFormat(textFormat);
- trace("textWidth with a scaling of 1: "+scaleMe.textField.textWidth);
- scaleMe.textField._width = scaleMe.textField.textWidth+10;
- scaleMe.textField._height = scaleMe.textField.textHeight+5;
- scaleMe._xscale=100;
- scaleMe._yscale=100;
- trace("textWidth with a scaling of 100: "+scaleMe.textField.textWidth);
- stop();
The TextField also mustn't be nested in a MovieClip with a _rotation!=0 or it wouldn't display at all!
Add this to the lines above and the text will disappear scaleMe._rotation=90;
System text cannot have _alpha values. It can only be hidden and shown with _visible
Add this to the lines above and nothing will happen: scaleMe._alpha=0;


