I'd like to send a dispatchEvent
to a loaded swf, put into a movieclip
. I found a good topic about it but my example doesn't work, the "trace" doesn't appear.
Edit.
- I have a
main.as
- another class:
submenu.as
, that I import inmain.as
- when I click on the "main" menu in
main.as
, I would like to send adispatchEvent
tosubmenu.as
(because I'd like the submenu to change one of its items, when I click on the "main menu" inmain.as
, so I need to send adispatchEvent
tosubmenu.as
) - so I put a
dispatchEvent
in the methodclickButton
in mymain.as
:Event.CHANGE
- and in the
submenu.as
, I'd like to listen to thisevent.CHANGE
, and that's what I wrote below
End of edit.
In my parent class: each time I click on the menu:
dispatchEvent(new Event(Event.CHANGE));
or
stage.dispatchEvent(new Event(Event.CHANGE));
and in my child class :
public function initStage (e:Event){
[…]
this.parent.addEventListener(Event.CHANGE, switchItem, false, 0, true);
private function switchItem(pEvent:Event):void
{
trace("PARENT_CHANGED");
}
Any idea?
As far as I can tell that topic doesn't apply too much to you, unless you actually are loading a swf at runtime and are trying to listen to events between them. I would also advise not using hierarchy on the display list for gathering references unless the hierarchy itself is indeed important. For example, maybe this menu removes itself from its parent container on close, or needs to add a displayObject to the same container its on, and doesn't care what the container is. Using hierarchy forces you to maintain that hierarchy for the references, which can sometimes make it hard to make changes on a growing application. Heres an example of what you may be looking for that doesn't use the display list to gather references:
Heres an example using the display list hierarchy (I wouldn't recommend it) :