嵌入 SWC 无法访问文本字段

发布于 2024-12-04 03:29:17 字数 567 浏览 1 评论 0原文

我将带有影片剪辑资源的 SWC 添加到我的 Flash 构建器项目中。我可以使用点语法访问所有影片剪辑,但是当我尝试访问我的文本字段时,它会抛出一个错误,指出无法访问空对象引用的属性或方法

这是我的代码:

// gameMenuLevels is a main asset.
this.object = new gameMenuLevels();

这一切都正常,我可以深入两层:

var levelString:String = "level" + Utils.zeroPad(i + 1, 3);
var level:MovieClip = this.object[levelString] as MovieClip;
var bronze:MovieClip = level.bronze as MovieClip;

但是当我尝试获取我的文本字段时:

(bronze.getChildByName("levelNumber") as TextField)

它会抛出错误。

I added a SWC with movieclip assets to my flash builder project. I can access all movieclips with dot syntax but when I try to access my textfields it throws an error saying it is cannot access a property or method of a null object reference

Here is my code:

// gameMenuLevels is a main asset.
this.object = new gameMenuLevels();

This all works fine, I can go two levels deep:

var levelString:String = "level" + Utils.zeroPad(i + 1, 3);
var level:MovieClip = this.object[levelString] as MovieClip;
var bronze:MovieClip = level.bronze as MovieClip;

But when I try to get my textfield:

(bronze.getChildByName("levelNumber") as TextField)

It throws the error.

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

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

发布评论

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

评论(1

池木 2024-12-11 03:29:17

好的,通过尝试和错误,并从这个答案到另一个问题的帮助: SWC Instance name on movieclips?

我发现必须为所有子元素提供链接名称(导出到动作脚本)和实例名称。完成后,我就可以将子元素作为属性进行访问。希望这对其他人有帮助。

Okay with trial and error and help from this answer to another question: SWC Instance name on movieclips?

I found had to give all my child elements a linkage name (export to actionscript) and an instance name. Once that was done I could then access the child elements as a property. Hopefully this helps someone else.

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