错误 2006 提供的索引超出范围

发布于 2024-10-31 07:41:31 字数 251 浏览 0 评论 0原文

不幸的是,有一天另一个问题 - 这段代码的最后一行是罪魁祸首:

                    uiBar = new mcUiBar();
        uiBar.x=-15;
        uiBar.y=-5;
        addChildAt(uiBar, numChildren-1);

现在我研究了,所以我知道它与数组比任何东西都大有关,但我没有弄清楚。我很困惑。我将不胜感激你的帮助。干杯

Another day another problem unfortunately- the last line of this piece of code is the culprit:

                    uiBar = new mcUiBar();
        uiBar.x=-15;
        uiBar.y=-5;
        addChildAt(uiBar, numChildren-1);

Now I researched and so I know it has something to with the array being larger than whatever, but I'm not figuring it out. I'm stumped. I would appreciate your help. Cheers

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

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

发布评论

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

评论(2

梦醒灬来后我 2024-11-07 07:41:31

超出范围错误基本上是说您为索引提供的值“超出显示对象容器中索引数组的范围”。可接受的范围是从 0n+1,其中 n 是最顶层子项的索引。另一种说法是 0numChildren。所以乔治是对的,当numChildren - 1 = -1时你就会遇到问题。

如果您尝试将子级添加到next-to-top层,请使用上面的 if 语句。但是,如果您只是尝试将其添加到顶层,则应该使用同义的 addChildAt(child, numChildren)addChild(child)

The out of range error basically is saying that the value you're providing for the index is "out of range" of the array of indexes in the display object container. The acceptable range is from 0 to n+1 where n is the topmost child's index. Another way to say this is 0 to numChildren. So George is right, you're going to have problems when numChildren - 1 = -1.

If you're trying to add the child to the next-to-top layer, use the if statement above. However, if you're just trying to add it to the top layer, you should either use addChildAt(child, numChildren) or addChild(child) which are synonymous.

画离情绘悲伤 2024-11-07 07:41:31

代码太少,但最后一行:
addChildAt(uiBar, numChildren-1); 似乎是问题所在。

如果还没有添加子项(numChildren 为 0)会发生什么?
这应该会引发错误,因为您尝试在深度/索引 -1 添加 uiBar

尝试 addChildAt(uiBar, numChildren > 0 ? numChildren-1 : 0);

Too little code, but that last line:
addChildAt(uiBar, numChildren-1); seems to be the problem.

What happens if there are no children added yet (numChildren is 0) ?
That should throw an error because you're trying to add uiBar at depth/index -1

try addChildAt(uiBar, numChildren > 0 ? numChildren-1 : 0);

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