即使存在,也未找到父影片剪辑/舞台

发布于 2024-12-19 02:35:44 字数 271 浏览 5 评论 0原文

我想问这个经常出现在我脑海中的问题。

当我尝试删除影片剪辑时,为什么会出现此错误,提示父级不存在。在第一种情况下,如果电影剪辑没有被电影剪辑或舞台“包含”,则电影剪辑不能存在于屏幕/内存上。

这是怎么发生的,有人可以解释一下这个“电影剪辑”如何失去其对舞台或容器 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 技术交流群。

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

发布评论

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

评论(2

谁的年少不轻狂 2024-12-26 02:35:44

这种情况有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

捂风挽笑 2024-12-26 02:35:44

即使没有父级,影片剪辑也可以存在。看看这些相当标准的代码行:

var myThing:MovieClip = new ThingThatExtendsMovieClip();
// at this point in time myThing DOES exist yet does not have a parent

// now let's give it a parent
addChild(myThing);

// and if we remove it again: 
removeChild(myThing);

// myThing again exists without a parent. 

这里的技巧是,如果没有任何东西保留对 myThing 的引用,它最终将消失。 但是只要您保留对它的引用,无论是将其作为子项还是存储在变量中,它都会保留下来。父母与否。

MovieClips can very much exist even though they do not have a parent. Look at these rather standard lines of code:

var myThing:MovieClip = new ThingThatExtendsMovieClip();
// at this point in time myThing DOES exist yet does not have a parent

// now let's give it a parent
addChild(myThing);

// and if we remove it again: 
removeChild(myThing);

// myThing again exists without a parent. 

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.

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