2012-04-12 67 views
3

此代码抛出一个错误:ActionScript:这怎么会失败?

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. 

怎么能这样呢?我正在检查是否它是一个孩子事先。

+0

你可以发布代码,你检查它是否是一个孩子? – 11684 2012-04-12 09:02:00

+0

检查是否包含() – clamp 2012-04-12 09:05:20

+0

oops ,误读... – 11684 2012-04-12 12:40:51

回答

5

将返回true,如果主题是调用者的后代。这将返回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; 
} 
相关问题