Flash AS3 ReferenceError:错误#1056:无法在 flash.text.TextField 上创建属性字体

发布于 2024-10-19 11:15:14 字数 996 浏览 1 评论 0原文

首先让我警告您,我是“老派”,即代码在我的时间线上,唯一使用的类是当我向 Script1.swf 添加几种新字体时自动创建的类,Script1.swf 是我的嵌入字体的电影剪辑。

在名为 Round.fla 的主影片剪辑的第一帧上,我使用加载器对象加载了包含字体的 Script1.swf。我使用的跟踪语句显示 Script1_lb.swf 已加载。

我正在使用带有影片剪辑图标(示例字体的 jpg 图片)的列表框(script1_lb),数据是字体类的名称,如下所示:

script1_lb.dataProvider.addItem( {icon:akaDora_mc, data:"akaDora"} );

我想将字体应用到已经存在的文本字段(design_mc.info_txt)存在于舞台上,所以这是我使用的代码:

import flash.text.Font;
import flash.text.TextField;
var tff:TextFormat = new TextFormat();
var font:Font=new Font();

script1_lb.addEventListener(Event.CHANGE,getFont);

function getFont(event:Event):void {
tff.font = script1_lb.selectedItem.data;
MovieClip(parent).design_mc.info_txt.embedFonts = true;
MovieClip(parent).design_mc.info_txt.setTextFormat(tff.font);

}

当尝试应用字体 akaDora 时,这是我收到的错误:

TypeError: Error #1034: Type Coercion failed:无法将“akaDora”转换为 flash.text。文本格式。

我已经看了几个小时并阅读了帮助文件,但似乎看不出我可能缺少什么。有人可以帮忙吗?谢谢

First let me warn you that I’m “old school” i.e. code is on my timeline and the only classes used were those automatically created when I added several new fonts to Script1.swf which is my movieclip for embedded fonts.

On the first frame of my main movieclip which is named Round.fla, I have loaded Script1.swf that contains the fonts using the loader object. I'm using a trace statement that shows that Script1_lb.swf is loaded.

I am using a listbox (script1_lb) with movieclip icons (jpg picture of the sample font) and the data is the name of the font class, like this:

script1_lb.dataProvider.addItem( {icon:akaDora_mc, data:"akaDora"} );

I want to apply the font to a text field (design_mc.info_txt) that already exists on the stage so this is the code I used:

import flash.text.Font;
import flash.text.TextField;
var tff:TextFormat = new TextFormat();
var font:Font=new Font();

script1_lb.addEventListener(Event.CHANGE,getFont);

function getFont(event:Event):void {
tff.font = script1_lb.selectedItem.data;
MovieClip(parent).design_mc.info_txt.embedFonts = true;
MovieClip(parent).design_mc.info_txt.setTextFormat(tff.font);

}

When trying to apply the font akaDora, this is the error I’m getting:

TypeError: Error #1034: Type Coercion failed: cannot convert "akaDora" to flash.text.TextFormat.

I’ve been looking at this for hours and reading the help files but can’t seem to see what I might be missing. Can someone help? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

留一抹残留的笑 2024-10-26 11:15:14

看来您试图将文本格式设置为 TextFormat 对象的字体而不是实际的 TextFormat,setTextFormat() 方法接受它作为参数:

您有这样的:

MovieClip(parent).design_mc.info_txt.setTextFormat(tff.font);

将其更改为这样:

MovieClip(parent).design_mc.info_txt.setTextFormat(tff);

it appears your trying to set the text format as your TextFormat object's font rather than the actual TextFormat, which the setTextFormat() method accepts as it's parameter:

you have this:

MovieClip(parent).design_mc.info_txt.setTextFormat(tff.font);

change it to this:

MovieClip(parent).design_mc.info_txt.setTextFormat(tff);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文