flash cs4,动态文本字段
通常我很擅长使用as3,但这真的让我很头疼,
我有下面的代码,一切正常,我可以跟踪输出,但文本仍然没有在舞台上显示任何线索?
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);
}
}
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您将文本字段放置在彼此的顶部。
You are placing the textfields on top of each other.
我看到的第一件事是在创建 TextField 的行上,它应该是:
另外,尝试在不使用 setTextFormat() 的情况下执行此操作来检查问题是否是嵌入字体或其他问题。
First thing I see is on the line where you create the TextField it should be:
Also, try doing this without using setTextFormat() to check if the problem is the embedded font or something else.
使用这个
代替
这个也可以解决嵌入字体的问题。不过还是谢谢大家的帮助
Use this
instead of
this will solve the problem of embed fonts as well. Thank you everyone for the help though
确保您嵌入了字体并且它能够追踪文本字段的内容。
Make sure you embed the font and that it is tracing out what the textfield is saying.
我也有同样的问题。
根据 as3 TextField 文档:
换句话说,当您以编程方式添加字体时,您需要在舞台上有一些带有嵌入字体的动态文本字段,或者,您可以使用导出选项创建自己的字体符号到库并将其添加到您的TextField:
我想你现在已经明白了。我希望这对其他人有帮助=)
编辑:
在这种情况下,您应该使用
而不是
最后一个似乎对我不起作用。
I had the same problem.
According to the as3 TextField documentation:
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:
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
Instead of
The last one doesn't seem to work for me.