开发者

Does anybody know how to delete a parent instance from one of its children in AS 3?

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()" d开发者_开发知识库oesn't seem to be working. High-level explanation OK; I can post code (it's like four classes) if anybody wants to see specifics.


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.


for the button add an on-click event listener and then the function for it can be something like this

function onClick($e:MouseEvent):void{
  var parentMC:MovieClip = e.target.parent;
}

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜