Search code examples
flashactionscript-2flash-cs4movieclip

Flash + AS2 = Unload a movieclip itself when it is clicked


I have a movieclip which unloads two other movieclips when it is clicked. This bit works fine, but it should also remove itself after this, which particularly does not work. Here is my code, can someone please tell me what I am doing wrong:

close_button.onRelease = function() {
 background.unloadMovie();
 loading.unloadMovie();
 this.unloadMovie();
}

Regards and TIA

// edit

Here is the code I create the movieclips:

// load background, movieclip container (loading) and close button
var background:MovieClip = _root.attachMovie("mc_back","loading_background", 100000);
var loading:MovieClip = _root.createEmptyMovieClip("loading",_root.getNextHighestDepth());
var close_button:MovieClip = _root.attachMovie("close_button","close_button",_root.getNextHighestDepth());

I tried:

this._parent.close_button.unloadMovie(); // it removed the whole _root movieclip, as _root is the parent

and

_parent.close_button.unloadMovie(); // did just nothing

Both failed.


Solution

  • In the event handler, 'this' would refer to close_button, not the main movie. All you need to do is either declare a variable equal to this outside of the close button onRelease handler, or try this.parent.unloadMovie() (assuming the parent of the close button is the movie you're trying to remove).