Reputation: 13517
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.
Upvotes: 1
Views: 14071
Reputation: 11
a movieclip can not unload it's self because it cannot read a code that is not there so it does not unload in the first place.
Upvotes: 1
Reputation: 35838
Try
close_button.onRelease = function() {
background.unloadMovie();
loading.unloadMovie();
this.removeMovieClip(); // This 'removes' the movie clip
// which is the closest to 'unload'
}
Upvotes: 0
Reputation: 2832
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).
Upvotes: 0