开发者

What is the best approach to building a popup inside of Flash AS3

I am开发者_如何转开发 trying to accomplish an "imagemap" in flash where you click on different areas in the image and when you click on it, a popup (within flash) comes up showing more information about the object that was clicked on. The popup has a close button that can will then close the popup.

My biggest trouble is the way I have my code right now is when you click on a region of the map, it creates a popup on the fly, and then I use addChild(_myPopup) to add it to the display list. The problem with this approach for me, is that the Popup is now a Child of the button I just pressed, but this object organization doesn't really make sense to me. I'd like to have the popup not be a child of the button and it be on it's own layer or a child of the stage directly.

What is a good approach and code architecture for building such an organization of objects? I'm fairly new to AS3 and I've built some small applications but my knowledge is limited.

Thanks

UPDATE

ok looks like calling stage.addChild(myPopup) from inside the button works pretty well. Is this good practice?


Assuming you have a hierarchy that looks something like this:

stage
  Main class
    Image class
      Button

It's good practice to never call upwards in the displaylist, every object only deals with it's children. Events however, are a nice way of communicating upwards. Have the Button dispatch an event, preferrably a custom one, then handle that using a listener in the main class that then deals with creating a popup on top of everything.


An often encountered practise to organize the layers of the visible application is:

  • stage
    • main class with all children
    • popup container
    • tooltip container
    • mouse cursor container (apparently not longer necessary since player 10 supports custom cursors)

So you create your popups always in the popup container above the main class. If you would have tooltips, they should go into the tooltip container. This approach guarantees that popups are always visible above the main app and tooltips are always visible on top of everything.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜