# Controlling attachedMovie Clips

**URL:** <https://forum.kirupa.com/t/controlling-attachedmovie-clips/186984>\
**Category:** Uncategorized\
**Created:** [April 25, 2006, 8:41pm UTC](https://forum.kirupa.com/t/controlling-attachedmovie-clips/186984 "2006-04-25T20:41:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![halian](https://avatars.discourse-cdn.com/v4/letter/h/45deac/32.png) [@halian](https://forum.kirupa.com/u/halian)\
**Post date:** [April 25, 2006, 8:41pm UTC](https://forum.kirupa.com/t/controlling-attachedmovie-clips/186984/1 "2006-04-25T20:41:24Z")

</div>

I’m kinda new to using attachMovie and i was wondering how to control attached movies to do things onEnterFrame. Also if there’s a better way of writing this please let me know. Example:

```auto
_root.attachMovie("boxMC", "boxMC", _root.getNextHighestDepth());
_root.boxMC._alpha = 0;
_root.boxMC._x = 100;
_root.boxMC._y = 100;

```

now what if i wanted that to fade from 0 to 100 in intervals of 10.  
i thought i could write a function for it but apparently my function skills aren’t the greatest. I had something like

```auto
var fadeIn:Function = function(){
_root.boxMC._alpha += 10;
}
fadeIn();

```

---

<div class="post-metadata">

**Author:** ![watcher](https://avatars.discourse-cdn.com/v4/letter/w/77aa72/32.png) [@watcher](https://forum.kirupa.com/u/watcher)\
**Post date:** [April 25, 2006, 9:02pm UTC](https://forum.kirupa.com/t/controlling-attachedmovie-clips/186984/2 "2006-04-25T21:02:25Z")

</div>

Hi,

try this:

```auto
var mc:MovieClip = _root.attachMovie("boxMC", "boxMC", _root.getNextHighestDepth(), {_x:100, _y:100}); // returns a refference to newly created boxMC instance

// now with that refference, let's fade it In
mc.fadeIn = function() {
    this.onEnterFrame = function(){
          if(this._alpha >= 100)
            delete this.onEnterFrame; // also dont forget to kill this once it faded
          this._alpha +=10;
    }
}

// now run fadeIn
mc.fadeIn();

```

Now hope it all works, havent tested it but should be simple to understand and working 🙂

Cheers!

EDIT: works 🙂
