# Restarting a movie clip problem

**URL:** <https://forum.kirupa.com/t/restarting-a-movie-clip-problem/262494>\
**Category:** flash\
**Created:** [June 6, 2008, 11:51am UTC](https://forum.kirupa.com/t/restarting-a-movie-clip-problem/262494 "2008-06-06T11:51:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gloopy](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@gloopy](https://forum.kirupa.com/u/gloopy)\
**Post date:** [June 6, 2008, 11:51am UTC](https://forum.kirupa.com/t/restarting-a-movie-clip-problem/262494/1 "2008-06-06T11:51:58Z")

</div>

I have a very simple movie that randomly places a movie clip:

```auto
 
**Frame 1:**
i=0;
 
**Frame 2:**
_root.tile.duplicateMovieClip("tile"+i,i+1)
_root["tile"+i]._x=Math.random()*550+20;
_root["tile"+i]._y=Math.random()*320+20;
_root["tile"+i]._xscale=Math.random()*50+10;
_root["tile"+i]._yscale=Math.random()*90+8;
_root["tile"+i]._alpha=Math.random()*100+1;
_root["tile"+i]._rotation=Math.random()*45+10;
 
**Frame 3:**
if(i<30){
 ++i
 gotoAndPlay(2)
}else{
 gotoAndStop(1)
}

```

Once i gets to 30, the movie stops.

I want to remove all of the MCs via a button, and restart the movie.

I can remove them, but I can’t seem to restart the movie - by that I mean that the MCs are removed, but the movie doesn’t start again by randomly placing MCs - instead, one MC instance fires off, and then nothing. These are the actions on the button:

```auto
on (release) {
i=1; 
gotoAndPlay(1);
var i = 0; 
var ref = null;
for(i in this)
{
if(typeof (ref = this*) == "movieclip")
ref.removeMovieClip();
}
}

```

Files:  
swf: [[COLOR=#0000ff]http://jimpix.co.uk/gws02.swf[/COLOR]](http://jimpix.co.uk/gws02.swf)  
fla: [[COLOR=#0000ff]http://jimpix.co.uk/gws02.fla[/COLOR]](http://jimpix.co.uk/gws02.fla)

## Any ideas? Thanks.

[http://jimpix.co.uk/](http://jimpix.co.uk/)

---

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [June 6, 2008, 3:12pm UTC](https://forum.kirupa.com/t/restarting-a-movie-clip-problem/262494/2 "2008-06-06T15:12:30Z")

</div>

Put this code in the first frame. delete the other 2 frames

```auto

stop();
//
function setupTiles() {
    for (var i = 0; i<30; i++) {
        _root.tile.duplicateMovieClip("tile"+i, i+1);
        _root["tile"+i]._x = Math.random()*550+20;
        _root["tile"+i]._y = Math.random()*320+20;
        _root["tile"+i]._xscale = Math.random()*50+10;
        _root["tile"+i]._yscale = Math.random()*90+8;
        _root["tile"+i]._alpha = Math.random()*100+1;
        _root["tile"+i]._rotation = Math.random()*45+10;
    }
}
//
setupTiles();
//
tidy_btn.onRelease = function() {
    for (var i in this._parent) {
        if (typeof (this._parent*) == "movieclip" && this._parent*._name != "tile") {
            this._parent*.removeMovieClip();
        }
    }
    //
    this._parent.setupTiles();
};

```

And make sure you give your button an instance name - tidy\_btn - so the onRelease events work 😉

---

<div class="post-metadata">

**Author:** ![gloopy](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@gloopy](https://forum.kirupa.com/u/gloopy)\
**Post date:** [June 7, 2008, 7:45am UTC](https://forum.kirupa.com/t/restarting-a-movie-clip-problem/262494/3 "2008-06-07T07:45:28Z")

</div>

Thanks matthew - that works a treat!

---

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [June 7, 2008, 8:14am UTC](https://forum.kirupa.com/t/restarting-a-movie-clip-problem/262494/4 "2008-06-07T08:14:27Z")

</div>

No worries man, glad to help 😃
