PDA

View Full Version : removeMovieClip() does not work when adding UI components to the library?


KingBling
11-20-2005, 05:38 PM
Hi,
I have come accross some strange behaviour using removeMovieClip()...
Can someone please confirm this behaviour, or better yet, offer an explanation or solution to this...

In a new Flash document, I put this code in the first frame, which works fine:

// `````````````````````````````````````````````````` ``````
stop();
_root.attachMovie("myClip", "myClip_mc", this.getNextHighestDepth());

myClip_mc.onPress = function(){
trace(this.getDepth()); // output: 0
removeMovieClip(this);
}
// `````````````````````````````````````````````````` ``````


Now, I drag a UI component into my library, say a button component. When I test the movie now, the removeMovieClip no longer works. Also note the output of the .getDepth() trace...


// `````````````````````````````````````````````````` ``````
stop();
_root.attachMovie("myClip", "myClip_mc", this.getNextHighestDepth());

myClip_mc.onPress = function(){
trace(this.getDepth()); // output: 1048576
removeMovieClip(this);
}
// `````````````````````````````````````````````````` ``````

Can anyone help out here? How would I go about removing this movieclip?
:confused:
Thx

KingBling
11-20-2005, 06:19 PM
Aha, I have found an answer to my own question. For anyone having similar problems, here is the solution:

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 to getNextHighestDepth()returns 1048576, which is outside of the range at which MovieClip.removeMovieClip() can function (-16383,1048575). The call to removeMovieClip() then fails silently because it can't handle the out-of-range value.

This will fix the problem:
// `````````````````````````````````````````````````` ```````
stop();
_root.attachMovie("myClip", "myClip_mc", this.getNextHighestDepth());


myClip_mc.onPress = function(){
trace(this.getDepth()); // output: 1048576
this.swapDepths(1048575)
removeMovieClip(this);
}
// `````````````````````````````````````````````````` ```````

see http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_19435 for a more in-depth explanation.

Thx all.