Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

callback method vs event listeners

Community Beginner ,
Jul 27, 2014 Jul 27, 2014

I have developing a game in AS 3 with MVC pattern. In my document class, I have created around 15 event listeners to update the game view.

My question is instead of event listeners can I use call back function?.

I have tested the sample file by replacing the addeventlisteners with callback function. It is working fine.

I think compare to eventlisteners, call back will took less memory only ().

Any suggestion please?

thanks in advance

TOPICS
ActionScript
681
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jul 28, 2014 Jul 28, 2014

Callback functions are more performant. Event listeners allow for a higher degree of decoupling in some cases, because you often don't need to know where the thing is you're listening to and the thing dispatching the event doesn't need to know or care who, if anyone, is listening. And as soon as you need for more than one thing to listen, callbacks get more complex (see AS3 Signals).

With either callbacks or event listeners, keep in mind you are handing a reference to the listening object to the

...
Translate
Community Expert ,
Jul 28, 2014 Jul 28, 2014

yes, you can use call back functions.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 28, 2014 Jul 28, 2014
LATEST

Callback functions are more performant. Event listeners allow for a higher degree of decoupling in some cases, because you often don't need to know where the thing is you're listening to and the thing dispatching the event doesn't need to know or care who, if anyone, is listening. And as soon as you need for more than one thing to listen, callbacks get more complex (see AS3 Signals).

With either callbacks or event listeners, keep in mind you are handing a reference to the listening object to the dispatching object. Make sure to clean everything up when the listening object is no longer in use, or you can wind up with memory leaks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines