# Problems with fadein fadeout code

**URL:** <https://forum.kirupa.com/t/problems-with-fadein-fadeout-code/200901>\
**Category:** Uncategorized\
**Created:** [September 16, 2006, 10:49am UTC](https://forum.kirupa.com/t/problems-with-fadein-fadeout-code/200901 "2006-09-16T10:49:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![michelfeldman](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@michelfeldman](https://forum.kirupa.com/u/michelfeldman)\
**Post date:** [September 16, 2006, 10:49am UTC](https://forum.kirupa.com/t/problems-with-fadein-fadeout-code/200901/1 "2006-09-16T10:49:54Z")

</div>

This is a code for fading out an object.

```auto
function fadeOutObject(target) {
        onEnterFrame = function () {
        target._alpha -= 2;
        if (target._alpha < 0) {
            target._alpha = 0;
            delete onEnterFrame;
        }
    };
}

```

Now, let’s say I have a movie clip with the instance name of fadetest. If I write:

```auto
fadeOutObject(fadetest);

```

or

```auto
fadeOutObject(_root.fadetest)

```

it doesn’t work… (I’m going crazy with this)…  
but if I write:

```auto
fadeOutObject(_root);

```

, then it works… Could somebody explain this to me?
