Copy link to clipboard
Copied
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
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
...Copy link to clipboard
Copied
yes, you can use call back functions.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now