Why isn't there an event.type?

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

Post Reply
Devon
Posts: 41
Joined: 12 Apr 2011, 16:18

Why isn't there an event.type?

Post by Devon »

It'd be nice to have an event.type implemented into the API so that we have a little more control and flexibility on how we manage our events...
For example, event.type = SFS2X.SFSEvent.CONNECTION.

I forward my events to an observer to be handled by the application... However, as it is now, I have to create a specific function for each SFS event, modify the event object to include it's type, and then forward it to my observer.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Why isn't there an event.type?

Post by Lapo »

Hi,
I am not sure if I understand this correctly. Having dedicated function calls for each event is already the best way to handle events.
Using a global observer would lead to this code:

Code: Select all

function handler(event)
{
	if(event.type == CONNECT)
		handleConnect(event)
	else if if(event.type == LOGIN)
		handleLogin(event)
	//...
}
Which bring us back from where we started, with an additional passage.
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply