PDA

View Full Version : Dynamically adding TextField to MovieClip



psych
January 10th, 2008, 09:29 AM
I am trying to add TextField to a MovieClip using AS 3.0 with following code:


mc = new MovieClip();

mc.graphics.beginFill(0x000000);
mc.graphics.drawRect( 0, 0, 200, 200 );
mc.graphics.endFill();

var t:TextField = new TextField();
t.embedFonts = true;
t.antiAliasType = "advanced";
t.text = "TEST";

var tf:TextFormat = new TextFormat();
tf.color = 0xA5C71B;
tf.size = 30;
tf.font = "Arial";

t.setTextFormat(tf);
mc.addChild( t );

stage.addChild(mc);But the problem is that MovieClip (black rectangle) is displayed on stage but without the text. Anyone knows what's the problem?

thanks,
best regards

cheblin
January 10th, 2008, 10:47 AM
remove line

t.embedFonts = true;

psych
January 10th, 2008, 12:45 PM
remove line

t.embedFonts = true;

Thanks for suggestion but i tried that and didn't work. I am aware that i shouldn't be embedding Arial font which is preinstalled but i must have left that line because i tried before with some custom fonts.

cheblin
January 10th, 2008, 10:27 PM
Thanks for suggestion but i tried that and didn't work.

Befor reply I checked that in Flex Development and when I comment mentioned line it works for me fine.

My next suggestion is: try simplify your code till it start to work.