# Enter frame events, a question on optimisation

**URL:** <https://forum.kirupa.com/t/enter-frame-events-a-question-on-optimisation/319866>\
**Category:** flash\
**Created:** [March 7, 2011, 10:42am UTC](https://forum.kirupa.com/t/enter-frame-events-a-question-on-optimisation/319866 "2011-03-07T10:42:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffNevington](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jeffNevington](https://forum.kirupa.com/u/jeffNevington)\
**Post date:** [March 7, 2011, 10:42am UTC](https://forum.kirupa.com/t/enter-frame-events-a-question-on-optimisation/319866/1 "2011-03-07T10:42:24Z")

</div>

Lets say I am working on some basic shooting game that involves lots of moving enemies. The enemies all come from one class that extends movieclip.

I want the enemies to move 10px downwards every frame. At the moment I know of two ways of doing this:

The first is to run a single onEnterFrame function on the main timeline, this function loops through all of the enemies on the screen calling a function in the enemy class that contains “x+=10”.

The second is to put the onEnterFrame function inside the constructor function of the enemy class that would then contain the “x+=10”.

Both give the same result but is one less work for the computer than the other? The first has a big loop that accesses all of the enemies, the second has an “onEnterFrame” running for each of the enemies.

Thanks, Jeff
