PDA

View Full Version : [AS2] MediaDisplay component makes removeMovieClip not work


oakiedave
06-27-2009, 02:59 AM
I've run into a terrible problem. The person who can figure this out wins some kind of prize. If I have the 'MediaDisplay' component in the library and it has 'export for actionscript' checked in its properties, than with this code:

attachMovie("testeroo", "tester", _root.getNextHighestDepth());
trace('attached: ' + tester);
removeMovieClip(tester);
trace('after remove: ' + tester);

the removeMovieClip doesn't work!! If I uncheck the export for actionscript, this script works fine and the moveClip is removed. This makes no sense to me whatsoever. That component screws with a MoveClip's methods?

please help!
thanks in advance

oakiedave
06-27-2009, 06:42 PM
after half a day of banging my head against the wall, turns out that if you have a component in your movie, when it gets exported for actionscript in the first frame, it gets added at the highest depth level. So if you dynamically create a movie clip with getNextHighestDepth(), that depth is one more than is allowable in flash - then when you use removeMovieClip(), that movie exists in an invalid depth so it can't be removed. Neat, huh?

So the solution is to attach movies at a defined depth level instead of using getNextHighestDepth(). So for instance:

var depth:Number = 1000;
attachMovieClip("mc", "mc", depth);

then removeMovieClip(mc).

again this is only a problem if you have a component like MediaDisplay in your library exported for actionscript.

Forgot where I found this solution, but good karma to you!

CyanBlue
06-27-2009, 06:51 PM
Thanks for sharing the solution... ;)

Basically you can use the same script as your first post if you don't want to mess with the depth of the instance, and then use swapDepths() function to swap it to some known number that you'd like to dedicate for this reason, and then do removeMovieClip() after that...
This applies to the movieClip that's dragged onto the stage manually because you cannot simply remove it with removeMovieClip() function for it having the negative depth...
// Define this variable somewhere in frame 1 so that it is visible to everywhere or
// make it even a global variable if you want to make it easier...
var depthForDeletion:Number = 6666;

// Swap the depth before you delete...
mc.swapDepths(depthForDeletion);
// Remove it...
removeMovieClip(mc);
Here is Adobe TechNote that says the same thing...
http://kb2.adobe.com/cps/194/tn_19435.html

oakiedave
06-27-2009, 11:19 PM
thanks cyanblue.

funny, I spent half a day trying to figure out what was going on here through process of elimination, and just when I was about to give up, I did a search on removeMovieClip, and this explanation was like the 4th search result.

It really is these little kinks that drive me crazy sometimes. think I just have to improve my Sherlock Holmes skills!

CyanBlue
06-28-2009, 05:50 AM
Yeah... It's all about know-where thesedays... and Google does great job when we know what we are looking for... I believe this question was one of the favorite questions in the board as well... ;)