开发者

Usage of custom event with properties... Multiple events and single listener

I am having a hard time wrapping my head around what to do for the following situation:

  • I have multiple items in my app that I would like the user to click on. Some items are completely different classes.

  • The classes dispatch events and then when the events are captured, some modifications are done to the transform properties of a loosely coupled display object.

  • I want two separate classes to dispatch the same type of event, since I already have an image class that draws images based on a given url... I want开发者_如何学C the classes to dispatch the events, but then I think I want the difference to be detected when the event comes along... i.e., I would like to recognize the 'origin' or 'sub-type' of the event. Some sort of if/then logic would suffice.

Would it be better to have two separate types of events?

How do people normally do this?

Would anyone suggest creating some sort of variable to detect the 'sub-event-type' for the listener of the event?

Thanks for any thoughts...


The target property of the Event class contains the class that dispatched the event.You can query that property in your event handler to recognize the 'origin' of the event.

Creating a separate (sub)class for the event is another option that would work. I guess it depends on whether it's really the same logical event dispatched by different objects, or logically different events.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜