即使存在,也未找到父影片剪辑/舞台
我想问这个经常出现在我脑海中的问题。
当我尝试删除影片剪辑时,为什么会出现此错误,提示父级不存在。在第一种情况下,如果电影剪辑没有被电影剪辑或舞台“包含”,则电影剪辑不能存在于屏幕/内存上。
这是怎么发生的,有人可以解释一下这个“电影剪辑”如何失去其对舞台或容器 mc 的父引用吗? 。调试器堆栈将 movieclip.parent 的值显示为 null。
即使只是一条小评论也会非常有帮助。
谢谢
Vishnu Ajit
快乐编码
I'd like to ask this question which has been popping up on my mind often.
Why do i get this error saying parent does not exist when I try to remove a movieclip. In the first case, the movieclip cannot exist either on screen/memory if it was not 'contained' by either a movieclip or stage
How can this happen, can somebody explain how this "movieclip" loses its parent reference to the stage or container mc. The debugger stack shows the value of movieclip.parent as null.
Would be really helpful even if it were a small comment.
Thank you
Vishnu Ajit
happy coding
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这种情况有2种可能。
- 影片剪辑未添加到舞台或任何容器中。
- 或者它已经因代码中的其他错误而从父级中删除。
为了防止从父级删除影片剪辑时出现错误。
使用这个简单的代码来删除影片剪辑。
if(movieclip.parent)
movieclip.parent.removeChild(movieclip);
它将防止这个错误
there is 2 possibility in this case.
- either movieclip is not added to stage or any container.
- or it's already removed from parent with some other mistake in code.
To prevent error when remove movieclip from parent.
use this simple code to remove movieclip.
if(movieclip.parent)
movieclip.parent.removeChild(movieclip);
it will prevent this error
即使没有父级,影片剪辑也可以存在。看看这些相当标准的代码行:
这里的技巧是,如果没有任何东西保留对
myThing
的引用,它最终将消失。 但是只要您保留对它的引用,无论是将其作为子项还是存储在变量中,它都会保留下来。父母与否。MovieClips can very much exist even though they do not have a parent. Look at these rather standard lines of code:
The trick here is that if nothing is keeping a reference to
myThing
it will go away eventually. But as long as you do keep a reference to it, be it as a child or stored in a variable, it will stick around. Parent or not.