Why isn't there an event.type?

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

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

Why isn't there an event.type?

Postby Devon » 03 Jan 2013, 02:41

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: 21228
Joined: 21 Mar 2005, 09:50
Location: Italy

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

Postby Lapo » 03 Jan 2013, 09:33

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

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 3 guests