嵌入 SWC 无法访问文本字段
我将带有影片剪辑资源的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,通过尝试和错误,并从这个答案到另一个问题的帮助: 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.