Restarting a movie clip problem

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

 
**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:

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]
fla: [COLOR=#0000ff]http://jimpix.co.uk/gws02.fla[/COLOR]

Any ideas? Thanks.

http://jimpix.co.uk/

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


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 :wink:

Thanks matthew - that works a treat!

No worries man, glad to help :smiley: