Why embedding fonts to a dynamic TextField draws a blank!- Flex you suck
Filed under Lab Work, Programming | Tags:textfields
I promised i would write about this because it had both me and my team baffled for over a day. First off, we were using Flex in the project- although the only differences are the UI prefix before TextField and MovieClip, essentially the outcome is/was the same. Everytime we added a dynamic new TextField to a class, we had to apply the same styleSheet and fonts. We embeded the fonts to an external SWF. The styleSheet was also external. For our readers how prefer bullets, here you go:
The Goal-
- using a custom class, import a stylesheet, xml(for text) and a SWF filled with your embeded font(s)
- Using the LoaderInfo class, extract your fonts by their CLASS name for later use
- create a dynamic TextField (var tf:TextField), apply the stylesheet and ebedFonts attribute
- apply the text
- addChild(tf);
- an unexplainable empty text box
- add your text box first to an empty MovieClip
- do your text stuff in this oredr: new TextField (tf),tf.styleSheet= , tf.embedFonts=true, tf.htmlText=
- add the mc to the stage
- LAST- add your textfield to the mc (mc.addChild(tf))
var mc_title:UIMovieClip= new UIMovieClip()
mc_title.mouseEnabled=false;
var tx_title:UITextField = new UITextField();
tx_title.styleSheet=css
tx_title.embedFonts=embedding
tx_title.htmlText = xml.title;
tx_title.x = 228;
tx_title.y = 75;
tx_title.width = 500;
mc_title.addChild(tx_title)
container.addChild(mc_title);
- create the empty mc as a shell
- then your textfield
- FIRST apply the stylesheet (and make sure you really have imported and equated it to the StyleSheet class!!!)
- NEXT, embedFonts=true
- now your htmlText
- properties
- add the mc to the class (or stage, or wherever)
- FINALLY….add the textfield to the mc- this apparently must be last