Event Dispatching

Is it possible to dispatch custom events from any displayObject. I dont fully understand how the event sytem works
for events other than Runtime events…

thx
Laurent [import]uid: 3844 topic_id: 351 reply_id: 300351[/import]

Yes, any sample code for creating custom events would be very helpful.

.phil [import]uid: 4366 topic_id: 351 reply_id: 569[/import]

To clarify, I’m interested in creating events that any object can subscribe to. I.e. so on object can generate an event, and multiple other objects can subscribe to listen for this event. [import]uid: 4366 topic_id: 351 reply_id: 586[/import]

It’s definitely possible (although not currently documented!) to create a custom event, and then have multiple display objects subscribed to that event.

Can you specify what you’d like to do, so we can write some sample code? I know this would be useful to other people. [import]uid: 3007 topic_id: 351 reply_id: 641[/import]

Basically, I’d like to be able to dispatch events and have them received just like “touch” or other system events are received. In other words, have objects be able to register via addEventListener for a specified event, and have a function to handle it. Then I should be able to dispatch the corresponding event from elsewhere in my code. The event should include the event object as it does now with the standard events, so we can pass along the event.target, as well as any custom info we want to (e.g. event.status)

So for example, as I create display objects on the screen, I want to subscribe them to my custom event. Then based on other activity some code will dispatch (i.e. broadcast) an event, and any of the objects on the screen that subscribed will receive the event and handle it with the function specified in the addEventListener call that did the subscription.

Hope that helps.

.phil [import]uid: 4366 topic_id: 351 reply_id: 739[/import]

Phillip

Are you referring to observer/listener/broadcaster Object Oriented Principles? but you want to be able to dispatch them as events?

Carlos [import]uid: 24 topic_id: 351 reply_id: 743[/import]

I’m not tied to any particular model. I just want a series of display or other objects to be able to subscribe to a custom event I create. And then have another object be able to generate that event. It could work exactly like you’ve implemented touch or tap events using addEventListener() - I just want a way to be able to create my own events that I can trigger. For example, maybe there is a button on screen that when it is tapped by the user, it generates a “toggleHide” event. Those display objects that have subscribed to this “toggleHide” event will respond by making themselves invisible or visible depending on their current state. [import]uid: 4366 topic_id: 351 reply_id: 745[/import]

Hey Evan or Carlos, anyone who can help really, I noticed this thread went dead. I was thinking my question may go right along with it.

I’m creating a program that basically displays a random image when I shake.

My problem is how to display a new random image upon each new shake event?

Any help is greatly appreciated.

[import]uid: 3715 topic_id: 351 reply_id: 798[/import]

I think i answered your shaken question on the other thread.

For the event, we have a solution but i want to make sure we document it right and provide you with the right syntax.

carlos [import]uid: 24 topic_id: 351 reply_id: 803[/import]

Bumping this topic and wondering if you might have some sample code soon. Thanks!

.phil [import]uid: 4366 topic_id: 351 reply_id: 1174[/import]