views:

960

answers:

6

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);

}

}

+1  A: 

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
Amarghosh
i still should be able to see text on top of each other right?
how about setting `labels.text = "some hard coded value";` - does it work?
Amarghosh
+1  A: 

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.

Sandro
Though it doesn't look nice, it's okay to call constructors like that if there's no parameter involved
Amarghosh
commenting out formatting is worth a try I believe
Amarghosh
I did and nothing changed so far
Emdedded fonts in Flash can get pretty tricky.
Sandro
Is your trace working? Try tracing the XML side-by-side to the TextField.text
Sandro
trace is working fine and i can see the results there but no display
got it!!.. it was embed font i just commented that out
Good! Embedding a font is pretty easy, but you gotta follow all the steps. http://www.adobe.com/devnet/flash/quickstart/embedding_fonts/
Sandro
A: 

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

I started to have the same problem with embedded fonts right after i cleaned up my library. defaultTextFormat doesn't help though.
negative
A: 

abs.text="the event occured" + event.target.name;

abs is a dynamic text field.

the output text will show on the dynamic text field abs.

  • event.target.name its use for an event only dont lose time for thinking this .

dont use trace for this

Syam
A: 

Make sure you embed the font and that it is tracing out what the textfield is saying.

Flash Developer
A: 

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.

negative