A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: dispatchEvent() vs calling functions

  1. #1
    Member
    Join Date
    Nov 2005
    Posts
    75

    Question dispatchEvent() vs calling functions

    I am faily new to the Events framework in AS3 and only got into the built-in events that came with flash already like CLICK and enterFrame cos that was in AS2 as well. Im fairly new to this concept that AS3 can dispatch "custom events". My question is that whats the difference between dispatching an event, catching it with a listener and as result, deploy a function OR just simply instead of dispatching an event, simply call the function you want, u just dont use a listener anymore. I am sure that eventDispatcher() is way more flexible and i just need someone to paint the bigger picture for me becuase I honestly see no differnce between the two.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The difference is that with the event model, you can decouple the listeners and the dispatchers. If you wanted to call a function directly, you would have to have a reference to the object with that funtion (or at the very least, the function itself).

    With the event model, what you're doing is essentially saying "Hey! whoever cares, act on this!".

    It's much easier to add multiple listeners in the event model, and also swap out what happens on the event. As with so much else in object oriented design, it's about insulating parts from each other.

  3. #3
    Member
    Join Date
    Nov 2005
    Posts
    75
    ok thnx, so there isnt a big difference, just very small difference?

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Yes and no. In concept it's a slight difference. In effect it can be huge. Imagine if all tv stations had to directly manipulate your tv in order to show you programming. That would imply a) they have some measure of control over your tv, and b) that's a ****load of tvs they have to mess with.
    That's why they don't do it that way. TV stations are dispatchers (broadcasters). Your tv is a listener. You tell your tv what to listen to, and you get to decide what to do with that signal (display it, record it, etc). The station doesn't even get to know you're there. Unless you sign up with Nielsen, and that's a whole different story.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center