# Code works, but not inside of a class

**URL:** https://forum.kirupa.com/t/code-works-but-not-inside-of-a-class/152743
**Category:** Uncategorized
**Created:** [June 27, 2005, 3:49am UTC](https://forum.kirupa.com/t/code-works-but-not-inside-of-a-class/152743 "2005-06-27T03:49:17Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mprzybylski](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mprzybylski/32/613_2.png) [@mprzybylski](https://forum.kirupa.com/u/mprzybylski)
#### Post date: [June 27, 2005, 3:49am UTC](https://forum.kirupa.com/t/code-works-but-not-inside-of-a-class/152743/1 "2005-06-27T03:49:17Z")

</div>

i’m using "iloveitaly"s easing scrollbar class, and it works great. however, i added an effect that i want on my scrollbar, and it doesnt work quite how it should. what should happen is when u press the dragger, it should duplicate itself and then fade out, giving it kinda a “mouse trail” type effect i guess you can call it. anyway, here is the code for the part in the class that doesnt work:

```auto
private function onPress() {
        startDrag(this, false, lockPos[0], lockPos[1], lockPos[2], lockPos[3])
        // this is where the code that doesnt work starts
        this.onEnterFrame = function() {
            var nextDepth = this._parent.getNextHighestDepth();
            var dupe = this.duplicateMovieClip("dupe" + nextDepth, nextDepth);
            dupe._x = this._x;
            dupe._y = this._y;
            dupe.onEnterFrame = function() {
                this._xscale -= 10;
                this._yscale -= 10;
                this._alpha -= 10;
                if (this._xscale <= 0) {
                    this.removeMovieClip();
                }
            };
        };
        // this is where the code that doesnt work stops
    }

```

as u can see by the comments, if i take out that block of code, everything works fine. but if i leave it in for the desired effect, it duplicates the clips, but they end up staying on the canvas (some of them disappear, some dont) and then when i release-click again, i’m grabbing the duplicated instances and it no longer scrolls. i’m not very familiar with coding inside of class files, but if i use that code in a separate file, it did exactly what i wanted. any help is greatly appreciated. thanks in advance.
