# URGENT: Trouble loading and unloading movieclips in the same button - only works once

**URL:** <https://forum.kirupa.com/t/urgent-trouble-loading-and-unloading-movieclips-in-the-same-button-only-works-once/325263>\
**Category:** flash\
**Created:** [October 5, 2011, 3:11pm UTC](https://forum.kirupa.com/t/urgent-trouble-loading-and-unloading-movieclips-in-the-same-button-only-works-once/325263 "2011-10-05T15:11:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jen\_wen](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jen\_wen](https://forum.kirupa.com/u/jen_wen)\
**Post date:** [October 5, 2011, 3:11pm UTC](https://forum.kirupa.com/t/urgent-trouble-loading-and-unloading-movieclips-in-the-same-button-only-works-once/325263/1 "2011-10-05T15:11:55Z")

</div>

Hello all,  
I’m trying to load and unload a MovieClip with the same button. And it works, but it will only let me load and unload the MC once. After the first time, it stops loading. I believe this is because after the first load it only reads the unload code. I’m not sure how to solve this, here’s my code:

[LEFT]my\_btn.onPress = function()  
{  
captionFNtst(true,“tst”,this);  
this.onPress = function()  
{  
captionFNtst(false);  
};  
};

captionFNtst = function (showCaption, captionText, bName)  
{  
if (showCaption)  
{  
\_root.createEmptyMovieClip(“tst”,this.getNextHighestDepth(),{\_x:100, \_y:100});  
if ((bName.\_width + bName.\_x + tst.\_width) \> Stage.width)

```
    {
        xo = 0 - tst._width;
        yo = 0;
    }
    else
    {
        xo = 0;
        yo = 0;
    }
    tst.onEnterFrame = function()
    {
        tst._x = 100;
        tst._y = 100;
        tst._visible = true;
    };
}
else
{
    delete tst.onEnterFrame;
    tst._visible = false;
}

```

};

[/LEFT]

I’ve also tried this suggested code, but it doesn’t work at all when I use this version:

[COLOR=#000000]load\_movie = false;

my\_btn.onPress = function()  
{  
load\_movie = !load\_movie;  
};

if(load\_movie == true){  
captionFNtst(true,“tst”,this);  
} else {  
captionFNtst(false);  
}

captionFNtst = function (showCaption, captionText, bName)  
{  
if (showCaption)  
{  
\_root.createEmptyMovieClip(“tst”,this.getNextHighestDepth(),{\_x:100, \_y:100});  
if ((bName.\_width + bName.\_x + tst.\_width) \> Stage.width)

```
    {
        xo = 0 - tst._width;
        yo = 0;
    }
    else
    {
        xo = 0;
        yo = 0;
    }
    tst.onEnterFrame = function()
    {
        tst._x = 100;
        tst._y = 100;
        tst._visible = true;
    };
}
else
{
    delete tst.onEnterFrame;
    tst._visible = false;
}

```

};  
[/COLOR]  
Is there some code I can add at the end to get the actions to start again from the top? Any help is very much appreciated.  
Thanks,  
Jennifer
