从其他类访问变量返回 null

发布于 2024-11-06 03:14:05 字数 1075 浏览 1 评论 0原文

我做了一个单独的levelData类,以便能够灵活地添加级别。我对此很满意,直到我的主管命令我将 levelData 转换为 XML。我制作了 levelData 数据的 XML 版本(问题、答案、正确答案...)。我使用了旧的类并对其进行了转换,以便它可以获取 XML。

一切似乎都很好,我做了答案数组的痕迹,并且打印得很好......

但是当我尝试这个时,头痛开始了。

// This code appears in a different class with
// currentLvl:LevelData initialized in the constructor.
quizHolder.ansA.ansHud.text = currentLvl.choices[1];
quizHolder.ansB.ansHud.text = currentLvl.choices[2];
quizHolder.ansC.ansHud.text = currentLvl.choices[3];
quizHolder.ansD.ansHud.text = currentLvl.choices[4];
// BTW, I can't make a for loop to do the same function as above. So wierd.

我尝试运行它。它返回:

TypeError: Error #2007: Parameter text must be non-null.
    at flash.text::TextField/set text()
    at QuestionPane/setQuiz()
    at QuestionPane/setQuestion()
    at QuestionPane()
    at LearningModule()

我哪里出错了?我尝试为其创建一个自定义 get 函数,却得到了相同的错误。提前致谢。如果我需要发布更多代码,我会很乐意这样做 =)

PasteBin 中的 LevelData 类: http://pastebin.com /aTKC1sBC

I did a separate levelData class to be able to flexibly add levels. I was happy with it until my supervisor ordered me to convert my levelData into XML. I did an XML version of the levelData's data (question, answers, correct answer...). I used the old class and converted it so that it fetches the XML.

All seems well, I did traces of my answers array and it printed nicely...

But the headache started when I tried this.

// This code appears in a different class with
// currentLvl:LevelData initialized in the constructor.
quizHolder.ansA.ansHud.text = currentLvl.choices[1];
quizHolder.ansB.ansHud.text = currentLvl.choices[2];
quizHolder.ansC.ansHud.text = currentLvl.choices[3];
quizHolder.ansD.ansHud.text = currentLvl.choices[4];
// BTW, I can't make a for loop to do the same function as above. So wierd.

I tried to run it. it returned:

TypeError: Error #2007: Parameter text must be non-null.
    at flash.text::TextField/set text()
    at QuestionPane/setQuiz()
    at QuestionPane/setQuestion()
    at QuestionPane()
    at LearningModule()

Where did I go wrong? I tried making a custom get function for it, only to get the same error. Thanks in advance. If I need to post more of the code, I will gladly do so =)

LevelData Class in PasteBin: http://pastebin.com/aTKC1sBC

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

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

发布评论

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

评论(2

谎言 2024-11-13 03:14:06

如果没有看到更多的代码,就很难诊断,但是您在使用它之前是否正确初始化了选择数组?如果失败,我认为您需要发布更多代码。

另一个可能的问题是加载 XML 数据的延迟。确保在 QuestionPane 尝试访问数据之前已设置数据。

Without seeing more of the code it's hard to diagnose, but did you correctly initialize the choices Array before using it? Failing that I think you'll need to post more code.

Another possible issue is the delay in loading the XML data. Make sure your data is set before QuestionPane tries to access it.

べ映画 2024-11-13 03:14:06

你什么时候打电话给

quizHolder.ansA.ansHud.text = currentLvl.choices[1];
quizHolder.ansB.ansHud.text = currentLvl.choices[2];
quizHolder.ansC.ansHud.text = currentLvl.choices[3];
quizHolder.ansD.ansHud.text = currentLvl.choices[4];

这些?您加载 XML,并在完成后填充数组,这是正确的。但是,当您访问(填充文本字段)选择数组时,XML 是否已加载并解析?

When did you call

quizHolder.ansA.ansHud.text = currentLvl.choices[1];
quizHolder.ansB.ansHud.text = currentLvl.choices[2];
quizHolder.ansC.ansHud.text = currentLvl.choices[3];
quizHolder.ansD.ansHud.text = currentLvl.choices[4];

these? You load the XML and on complete you fill the array, what is correct. but is the XML loaded and parsed to the time when you access (fill the TextFields) the choices array already?

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