Controlling attachedMovie Clips

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:

_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

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

Hi,

try this:

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 :slight_smile:

Cheers!

EDIT: works :slight_smile: