# Dynamically attach onEnterFrame to attached movieclips?

**URL:** <https://forum.kirupa.com/t/dynamically-attach-onenterframe-to-attached-movieclips/223552>\
**Category:** Uncategorized\
**Created:** [April 23, 2007, 9:26pm UTC](https://forum.kirupa.com/t/dynamically-attach-onenterframe-to-attached-movieclips/223552 "2007-04-23T21:26:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shellbryson](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@shellbryson](https://forum.kirupa.com/u/shellbryson)\
**Post date:** [April 23, 2007, 9:26pm UTC](https://forum.kirupa.com/t/dynamically-attach-onenterframe-to-attached-movieclips/223552/1 "2007-04-23T21:26:52Z")

</div>

This one has me stumped. I’m missing a trick here I think; so why doesn’t this work?

```auto

function makeClouds(clouds:Number) {
    for (var i=0; i < clouds; i++ ) {
        var cloudName:String = "cloud" + i + "_mc";
        var cloudStart:Number = Math.round(Math.random() * Stage.width);
        this.attachMovie("cloud_mc", cloudName, this.getNextHighestDepth()); 
        debugMessage(cloudName);
        this[cloudName]._x = cloudStart;
        this[cloudName].onEnterFrame = function() {
            debugMessage("moving: " + cloudName);
            
            if (this[cloudName]._x <= -100) {
                this[cloudName]._x = Stage.width;
            } else {
                this[cloudName]._x -= 3;
            }
        }
    }
}

```

The cloud mcs attach fine and are displayed… but only one of the buggers animates. No errors are displayed. Help!
