gpt4 book ai didi

ActionScript:这怎么会失败?

转载 作者:行者123 更新时间:2023-12-04 04:57:39 24 4
gpt4 key购买 nike

这段代码抛出一个错误:

    if (modalMessage != null && contains(modalMessage))
{
removeChild(modalMessage); // the error is here
modalMessage = null;
}

错误是:

[Fault] exception, information=ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

这怎么可能?我正在事先检查它是否是一个 child 。

最佳答案

如果主题是调用者的后代,

contains() 将返回 true。对于间接后代、 child 的 child 等,这也会返回 true。

Determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself. The search includes the entire display list including this DisplayObjectContainer instance. Grandchildren, great-grandchildren, and so on each return true.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#contains%28%29

你可以检查父级:

if(modalMessage && modalMessage.parent && modalMessage.parent == this)

或者,对于更通用的处置解决方案:

if(modalMessage) {
if(modalMessage.parent) DisplayObjectContainer(modalMessage.parent).removeChild(modalMessage);
modalMessage = null;
}

关于ActionScript:这怎么会失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10120352/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com