# Adding OnEnterFrame to a Loop

**URL:** https://forum.kirupa.com/t/adding-onenterframe-to-a-loop/250654
**Category:** flash
**Created:** [January 31, 2008, 2:12pm UTC](https://forum.kirupa.com/t/adding-onenterframe-to-a-loop/250654 "2008-01-31T14:12:10Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jeancnicolas](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jeancnicolas](https://forum.kirupa.com/u/jeancnicolas)
#### Post date: [January 31, 2008, 2:12pm UTC](https://forum.kirupa.com/t/adding-onenterframe-to-a-loop/250654/1 "2008-01-31T14:12:10Z")

</div>

I am placing via actionscript an entire grid of squares to fill the screen.  
They are placed on stage through a For loop.  
I would like each movieClip added to obtain a function (as you would use onClipEvent() if the movie Clip was already on the stage) …

But as these clips are being dynamically added - how or where would I add the function in the code?

```auto
sw = Stage.width/2;
sh = Stage.height/2;
h = 22; 
t = 10; 
for(i=0; i< t; i++){
   var xPos:Number = i*22;
   _root.attachMovie("wave","_mc"+*,this.getNextHighestDepth(),{_x:sw+xPos,_y:sh}) };

```

So I would like EACH attached \_mc to have an OnEnterFrame Event occurance … Where could I add the intended function … ie: this.\_x = \_root.\_xmouse;

Thanks!!!
