View Full Version : event listener from other classes
xEnOn
August 5th, 2007, 02:56 PM
i am dispatching a event from a movieclip class.
my document class could hear it if i do this:
addEventListener("onJump", jumpReceived, true);
apprently, i must set the last parameter of capture to true. otherwise, i won't get the dispatched event. i am not sure why though.
then now my problem comes when i am trying to listen to this event from one of the other movieclip classes. i did the same thing that i have done in my document class to listen to the event with the same callback function, but it doesn't seem to detect anything.
how could i listen to it from other movieclip classes?
thanks.
McGuffin
August 5th, 2007, 03:02 PM
path.to.movieclip.addEventListener("onJump", jumpListener);
Any object on the display list will receive events that are dispatched by it and its display list descendants(children, grandchildren, etc).
sangackt
August 5th, 2007, 05:48 PM
I think I ran into the same problem you did just recently.
I had a movieclip that I wanted to communicate to the tween object that was moving it. What I ended up doing is adding an eventlistener to the movieclip and do a dispatchevent inside the movieclip from whatever frame you desire. Then the movieclip object in the main class will get the event and its handler could send a message whatever other object that was in the main class/stage, the tween object in my case.
I did not need to set the boolean in the addeventlistener to true.
xEnOn
August 5th, 2007, 09:21 PM
path.to.movieclip.addEventListener("onJump", jumpListener);
Any object on the display list will receive events that are dispatched by it and its display list descendants(children, grandchildren, etc).
i will not know the path to the movieclip because the movieclip that dispatches the event is created dynamically. in another words, it is quite difficult for me to know which is the movieclip that has dispatched it. is there any way where i could do a global event where all of my components will receive it?
xEnOn
August 5th, 2007, 11:37 PM
and when i try to do a direct path to the addListenerEvent in the constructor, i get an error of:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
nevertheless, if i try to do it in another function in the class and call the function after instantiating the class, it works.
why is it so?
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.