How do I define my own event listeners in AS3? I know it has to do with dispatch event, but I’m pretty much lost on how to use it.
I’m writing custom classes.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you don’t need to pass arguments with the events, just using a string like erkmene said will work.
The listener:
The dispatcher:
Make sure the class dispatching the event extends EventDispatcher either directly or somewhere in the class hierarchy.
The above code works but its best if the dispatching object holds the names of the events that it dispatches in static constant variables.
The listener:
The dispatcher: