# Trouble targeting a function

**URL:** <https://forum.kirupa.com/t/trouble-targeting-a-function/204158>\
**Category:** Uncategorized\
**Created:** [October 17, 2006, 3:43pm UTC](https://forum.kirupa.com/t/trouble-targeting-a-function/204158 "2006-10-17T15:43:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![crobar](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/crobar/32/2073_2.png) [@crobar](https://forum.kirupa.com/u/crobar)\
**Post date:** [October 17, 2006, 3:43pm UTC](https://forum.kirupa.com/t/trouble-targeting-a-function/204158/1 "2006-10-17T15:43:50Z")

</div>

ok so basicly what i want to create is a random card dealer.  
to start i want to deal 18 cards, but one at a time.

here is what i have so far:

```auto
nextcard = function () {
    this.onEnterFrame = function() {
        if (Math.round(this._x) == this.destX && Math.round(this._y) == this.destY) {
            //=======================================================
            _parent[this.myNextCard].nextcard();
            //=======================================================
            delete this.onEnterFrame;
        } else {
            this._x = this._x+(this.destX-this._x)/5;
            this._y = this._y+(this.destY-this._y)/5;
            this._rotation = this.rmax+(this.destY-this._y)/5;
            if (this._xscale>=100) {
                this._xscale -= 15;
                this._yscale -= 15;
            }
        }
    };
};
for (var i = 0; i<18; i++) {
    item = _root.attachMovie("card", "card"+i, i);
    item.myNextCard = "card"+(i+1);
    item._x = 0;
    item._y = 0;
    item._xscale = 200;
    item._yscale = 200;
    item.destX = Math.round(Math.random()*Stage.width);
    item.destY = Math.round(Math.random()*Stage.height);
    item.rmax = Math.round(Math.random()*225);
    if (i == 0) {
        item.onEnterFrame = function() {
        if (Math.round(this._x) == this.destX && Math.round(this._y) == this.destY) {
            //=======================================================
            _parent[this.myNextCard].nextcard();
            //=======================================================
            delete this.onEnterFrame;
        } else {
            this._x = this._x+(this.destX-this._x)/5;
            this._y = this._y+(this.destY-this._y)/5;
            this._rotation = this.rmax+(this.destY-this._y)/5;
            if (this._xscale>=100) {
                this._xscale -= 15;
                this._yscale -= 15;
            }
        }
    };
    }
}

```

the first card comes out, but i cant seem to attach the nextcard function to [myNextCard].  
is there a better way to pace this? or am i just targeting the function incorrectly?
