开发者

Best way to delete a duplicateMovieClip?

开发者 https://www.devze.com 2023-02-04 22:04 出处:网络
ham_mc.onPress=function(){ st开发者_运维问答artDrag(this); _root.ham_mc.swapDepths(getNextHighestDepth());
ham_mc.onPress=function(){
st开发者_运维问答artDrag(this);
_root.ham_mc.swapDepths(getNextHighestDepth());
}
ham_mc.onRelease=ham_mc.onReleaseOutside=function(){
stopDrag();
_root.ham_mc.duplicateMovieClip("ham_mc"+x,_root.getNextHighestDepth());
x++
}

This code just generates a new ham_mc where the user releases the original (drag and drop). The original returns to its starting point. I have the same code for a movieclip called cheese_mc, the user can drag and drop cheese too.

So, if more than one of these ham_mc's and cheese_mc's are created, what is the best way to delete the last one created?

I would like a simple button, lets call it delete_mc. The button is pressed, reversing the last duplicateMovieClip action. How do I implement this?


Store the last created MovieClip in a variable. Then use removeMovieClip();

_root.lastClip = null;

ham_mc.onPress=function(){
    startDrag(this);
    _root.ham_mc.swapDepths(getNextHighestDepth());
}
ham_mc.onRelease=ham_mc.onReleaseOutside=function(){
    stopDrag();
    _root.lastClip = _root.ham_mc.duplicateMovieClip("ham_mc"+x,_root.getNextHighestDepth());
    x++;
}

delete_mc.onRelease = function () {
    if (_root.lastClip != null) _root.lastClip.removeMovieClip();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号