Say I have a parent- and a child-object. At some point a variable (boolean) in the child changes and the parent needs to notice. Now, is it performance-wise cheaper to let the child dispatch an event once the variable has changed, or to have the parent check this childs variable every frame in an already existing enterFrameEventHandler?
dispatchEvent or checking variable every frame? What's better in a simple parent-child-relationship?
Asked
Active
Viewed 196 times
1
-
2simple - event over constant loop checking – Lukasz 'Severiaan' Grela Apr 05 '13 at 09:13
-
Agreed, event handling is almost always better. – LuigiEdlCarno Apr 05 '13 at 09:27
-
Thank you :) ! That's helpful to know. People say Events are bad for performance if you have to many of them. So, since the enterFrame-Event was already happening I thought perhaps one variable-check more in its eventHandler would hurt less than a new Event. But well, ok, Event is better! Looks cleaner as well! – Moritz Krohn Apr 06 '13 at 19:06
1 Answers
0
It is right. Event over loop check. But event better would be a callback. The event generation is heavy. If your variable or whatever changes quite often, then you would create a new Event instance every time a change happens.
Rob Penner wrode the library signals because of this problem:

Larusso
- 1,121
- 8
- 10
-
Thank you! I'm using the starling framework which features some kind of Event-recycling, so this won't be a problem :) . – Moritz Krohn Apr 06 '13 at 19:01