# Stuck on restarting a movie when loop completed

**URL:** <https://forum.kirupa.com/t/stuck-on-restarting-a-movie-when-loop-completed/301259>\
**Category:** flash\
**Created:** [December 6, 2009, 8:55am UTC](https://forum.kirupa.com/t/stuck-on-restarting-a-movie-when-loop-completed/301259 "2009-12-06T08:55:27Z")\
**Posts on this page:** 1\
**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:** [December 6, 2009, 8:55am UTC](https://forum.kirupa.com/t/stuck-on-restarting-a-movie-when-loop-completed/301259/1 "2009-12-06T08:55:27Z")

</div>

I have a simple FLA which loops through some keyframes and randomly places movie clips on the stage.

Frame 1:  
Contains nothing

Frame 2:

```auto
_root.tile.duplicateMovieClip("tile"+i,i+1)
_root["tile"+i]._x=Math.random()*800;
_root["tile"+i]._y=Math.random()*600;
this = Math.random()*100;
_root["tile"+i]._xscale=this;
_root["tile"+i]._yscale=this;
_root["tile"+i]._alpha=Math.random()*100+10;

```

Frame 3:

```auto
if(i<100){
    ++i
    gotoAndPlay(2)
}else{
    gotoAndStop(4)
}

```

Frame 4:

```auto
i=0;
stop();

```

On Frame 4, I add a button which I’d like to use to restart the whole thing.

The button has this AS on it:

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

```

But when I click the button, it doesn’t restart at all.

The SWF example is here:  
[http://jimpix.co.uk/junk/christmas-rainbows.swf](http://jimpix.co.uk/junk/christmas-rainbows.swf)

If it helps, the FLA is here:  
[http://jimpix.co.uk/junk/christmas-rainbows.fla](http://jimpix.co.uk/junk/christmas-rainbows.fla)

Any advice about what I’m doing wrong would be gratefully received.

Thanks!
