# gotoAndPlay in a class

**URL:** <https://forum.kirupa.com/t/gotoandplay-in-a-class/330533>\
**Category:** flash\
**Created:** [February 5, 2013, 8:12pm UTC](https://forum.kirupa.com/t/gotoandplay-in-a-class/330533 "2013-02-05T20:12:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Guardiola](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Marc\_Guardiola](https://forum.kirupa.com/u/Marc_Guardiola)\
**Post date:** [February 5, 2013, 8:12pm UTC](https://forum.kirupa.com/t/gotoandplay-in-a-class/330533/1 "2013-02-05T20:12:59Z")

</div>

Hello, I ll try to explain what im trying to do in a game. I spawn a monster on x=500 and he walks with an animation to x=100,(animation loop is from frame 1 to 6), i want to change that animation from frame 8 to 20 (attack animation) then play again the old loop.

In the mc i have one gotoAndPlay(1) on frame 6 and one gotoAndPlay(1) on frame 20

```auto
if (this._x > 100) {
            this._x -= 3;
        } else {
            damagetime++;
            if (damagetime== 50) {
                gotoAndPlay(8);
                            }
            if (damagetime== 60) {
                damagetime= 0;
            }
        }

```

this is how i spawn the monster

```auto
{
            var enemyout = _root.attachMovie("enemy1", "enemy1" + _root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:500, _y:random1});
            enemies.push(enemyout);
        }

```
