views:

26

answers:

1

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?

A: 

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.

grapefrukt
Thanks grapefrukt. It's good to know calls upwards in the display list is bad practice. Sending an event sounds great :)
justinl