removeMovieClip action fails when button component is on stage
Issue
In certain cases involvingMovieClip.getNextHighestDepth(), the removeMovieClip action will fail if a button component (or other v2 component) is also on the stage or in the Library.
Consider the following situation. Your Macromedia Flash file contains the following script, plus one instance of the Button component with the instance name "button_btn":
this.createEmptyMovieClip("myClip_mc", this.getNextHighestDepth()); myClip_mc.loadMovie("http://images.amazon.com/images/P/059600396X.01.MZZZZZZZ.jpg"); duplicateMovieClip(this.myClip_mc, "newClip_mc", this.getNextHighestDepth()); newClip_mc.loadMovie("http://images.amazon.com/images/P/1930727194.01.MZZZZZZZ.jpg"); newClip_mc._x = 200; this.button_btn.onRelease = function () { removeMovieClip(_root.newClip_mc); }
Note: Paste this code into a new movie and add a Button component to test.
In this case clicking the Button will not remove the duplicated MovieClip named "newClip_mc" as instructed.
Reason
If an FLA contains v2.0 components, the Flash DepthManager class (mx.managers.DepthManager) automatically reserves the highest upper and lower depths available to Flash (-16383,1048575) to use for tooltips and cursors. When that happens, a call togetNextHighestDepth()returns 1048576, which is outside of the range at which MovieClip.removeMovieClip() can function (-16383,1048575). The call toremoveMovieClip() then fails silently because it can't handle the out-of-range value.
Solution
There are several approaches to resolving this issue:
- Use
unLoadMovie()instead ofremoveMovieClip().this.button_btn.onRelease = function() { _root.newClip_mc.unloadMovie() }; - Swap the depth of the movie clip to a level at or below 1048575 before doing
removeMovieClip(). For example:
this.button_btn.onRelease = function() { _root.newClip_mc.swapDepths(1048575) removeMovieClip(_root.newClip_mc); }; - Use
mx.managers.DepthManager.kTopormx.managers.DepthManager.kTopmostto get the next highest depth rather than usinggetNextHighestDepth(). For details see "About the DepthManager class" in Flash MX 2004 Documentation. - For movies that do not require a v2.0 Button component, delete the Button component instances and delete the Button component from the file's Library. Then add a simple button symbol and assign necessary actions to the simple button.
For instance, in the above example, remove the Button component instance "button_btn", delete "Button" from the Library. Then add a button symbol of your own creation or an existing button from Window> Other Panels> Common Libraries> Buttons and give it the instance name "button_btn".
Additional information
For more information see "Movie Clip Depths" in Flash MX 2004 documentation.
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
