dispatchEvent or checking variable every frame? What's better in a simple parent-child-relationship?

219 Views Asked by At

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?

1

There are 1 best solutions below

1
On BEST ANSWER

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:

https://github.com/robertpenner/as3-signals