AS3如何从运行时添加的子级访问影片剪辑
我创建了一个将在运行时添加的子项。如何从子进程中访问主舞台上的影片剪辑?
I created a child that will be added on runtime. How do I access a movieclip on the mainstage from within the child?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最佳实践是将对已经在舞台剪辑中的引用从两者的容器传递给子实例,
这可以避免将结构信息硬编码到子实例中,这是面向对象的禁忌,并且通常会导致意大利面条式代码。
根据经验,对象通常应该只“了解”它们的直接子对象。
正如您从这个示例中看到的,子对象最终仍然会引用另一个对象,但它不需要知道它已经在舞台上,或者它的父对象是谁等。
Best practice would be to pass a reference to the already on stage clip, in to the child, from the container of both
This avoids hardcoding structural information into a child instance, which is an object oriented no-no, and usually leads to spaghetti code.
As a rule of thumb objects should usually only "know" about their direct children.
As you can see from this example the child object still ends up with a reference to the other one, but it doesn't need to know that it was already on the stage, or who its parent object is etc.