有谁知道如何从 AS 3 中的子实例之一删除父实例?
我正在 Flash 中编写一个小程序,该程序有一些小窗口,用户可以将其放置在画布上。我想在它们上面有一些“关闭”按钮,但是所说的按钮将是窗口实例的子级,并且有自己的类。由于 AS 3 没有全局变量,有人知道我该怎么做吗?调用“parent.parent.parent.deleteWindow()”似乎不起作用。高级解释OK;如果有人想查看具体细节,我可以发布代码(就像四个类)。
I'm putting together a small program in Flash that has little windows that the user can place on a canvas. I want to have little "close" buttons on them, but said buttons would be children of the window instance and have their own classes. Since AS 3 doesn't have globals, does anybody know how I could do this? Calling "parent.parent.parent.deleteWindow()" doesn't seem to be working. High-level explanation OK; I can post code (it's like four classes) if anybody wants to see specifics.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将希望您的 Button 类成为“EventDispatcher”。单击按钮时,您可以调度“closeEvent”并侦听窗口中的事件。这将允许您的窗口执行必要的逻辑来关闭和删除自身。
如果您希望主画布管理窗口,您可以让画布监听窗口上的事件。如果该事件在按钮上触发,它应该冒泡到您的窗口 UIComponent,并且 Canvas 可以删除调度“closeEvent”的任何窗口。
如果您提供代码示例,我可以给您一个更具体的示例。
You will want your Button class to be an 'EventDispatcher'. When the button is clicked you can dispatch your 'closeEvent' and listen for the event within your window. This will allow your window to perform the necessary logic for shutting down and removing itself.
If you want your main Canvas to manage the windows you can have your canvas listen for the event on the windows. If the event is fired on the button it should bubble up to your window UIComponent and the Canvas can remove any windows in which the 'closeEvent' is dispatched.
If you provide code samples I can give you a more concrete example.
为按钮添加一个单击事件侦听器,然后它的函数可以是这样的,
但这有点粗鲁,您应该考虑创建一种更安全的方法。
使用事件监听/调度或更好的信号、OOP、MVC RobotLegs等祝
你好运
for the button add an on-click event listener and then the function for it can be something like this
this is a bit of a brute approach though, and you should look into creating a safer approach.
Using event listenting/dispatching or better yet signals, OOP, MVC RobotLegs etc.
good luck