Reputation: 372
Usually i am pretty good at working my way round as3 but this one is really giving me a headache
I have this code below and everything works fine i can trace the output but still the text is not showing up on stage any clues??
import flash.display.Sprite;
import flash.text.TextField;
import flash.display.MovieClip;
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var total:XMLList;
var totalPram:XMLList;
var totalImgs:XMLList;
var totalX:XMLList;
var totalY:XMLList;
var totalInfo:XMLList;
var pram:XML;
var img:XML;
var playHead:Number=0;
var spacer:Number=20;
var xpos:Number=300;
var ypos:Number=100;
/////////////////////////////// formating ///////////////////////////////////
var newFormat:TextFormat = new TextFormat();// Text formating
newFormat.size=30;
newFormat.bold;
newFormat.font="Arial";
newFormat.color="0xCBFF00";
//newFormat.leading=-7;
////////////////////////////////////////////////////////////////////////////
xmlLoader.load(new URLRequest("info_1.xml"));
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
//var tagHolder:MovieClip = new MovieClip();
function LoadXML(e:Event):void {
xmlData=new XML(e.target.data);
xmlData.ignoreWhite=true;
Parseinfo(xmlData);
}
function Parseinfo(Details:XML):void {
total=Details.blink;
totalPram=Details.blink.tag;
totalInfo=Details.blink.more;
totalImgs=Details.blink.img;
totalY=Details.totalY.ypos;
totalX=Details.totalX.xpos;
for (var i=0; i<=1; i++) {
//addChild(tagHolder);
pram=totalPram[i];
var labels:TextField=new TextField ;// txtfield for questions to be displayed
labels.setTextFormat(newFormat);
//mytxt2.autoSize=TextFieldAutoSize.LEFT;
labels.embedFonts=true;
labels.text=pram;
labels.x=xpos+spacer;
labels.y=ypos;
trace(labels.text);
addChild(labels);
}
}
Upvotes: 0
Views: 2633
Reputation: 9225
I had the same problem. According to the as3 TextField documentation:
If you set the embedFonts property to true for a text field, you must specify a font for that text by using the font property of a TextFormat object applied to the text field. If the specified font is not embedded in the SWF file, the text is not displayed.
In other words you need to have some dynamic text field with embedded font on the stage when you add one programatically or, alternatively, you can create your own font symbol with Export option to the library and add it to your TextField:
var myFont:Font = new MyFont();
...
newFormat.font = myFont.fontName;
I guess you already figured it out by now. I hope it will be helpful for someone else =)
EDIT:
In this case you should use
labels.setTextFormat(newFormat);
Instead of
labels.defaultTextFormat = newFormat;
The last one doesn't seem to work for me.
Upvotes: 0
Reputation: 1
Make sure you embed the font and that it is tracing out what the textfield is saying.
Upvotes: 0
Reputation: 372
Use this
labels.defaultTextFormat=newFormat;
instead of
labels.setTextFormat(newFormat);
this will solve the problem of embed fonts as well. Thank you everyone for the help though
Upvotes: 0
Reputation: 4771
First thing I see is on the line where you create the TextField it should be:
var labels:TextField=new TextField();
Also, try doing this without using setTextFormat() to check if the problem is the embedded font or something else.
Upvotes: 1
Reputation: 59451
You are placing the textfields on top of each other.
var spacer:Number=20;
var xpos:Number=300;
var ypos:Number=100;
labels.x=xpos+spacer; //always 320
labels.y=ypos; //always 100
Upvotes: 1