A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Is dispatchEvent slower than code in class?

  1. #1
    Senior Member
    Join Date
    Jul 2004
    Posts
    264

    Is dispatchEvent slower than code in class?

    Hi guys,

    Does dispatchEvent use any extra memory/cpu/anything compared to calling a normal function?

    I plan to call it every couple of milliseconds for a timer.

    Many thanks!

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Yes there is slightly more overhead than using a callback. dispatchEvent requires you to instantiate an event object (which is the most expensive part) and then loop over listener lists to find an object registered for that event. A callback simply triggers a function already resident in memory.

    Events are still great for decoupling your code but callbacks are a nice way to optimize. Keep in mind that unless you're app is a game or game like, you may not notice a difference.

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You may also be able to keep a pool of Event objects in the dispatching instance to re-use rather than create new ones for every dispatch.

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