开发者

Flash: Adjust this code to keep the duplicated movie clip

OK, so here is my code

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

The user can at first drag the movie clip. When released, t开发者_如何学Gohe duplicateMovieClip command runs, leaving a new ham movie clip in the position the first is dragged to.

PROBLEM: When I click and drag the first ham movie click again, the duplicateMovieClip runs again but REPLACES the previous generated movie clip.

I added x and x++ in an attempt to give the movie clip duplication a different name every time, but this doesn't solve it.

How do I change this code so that a NEW ham_mc is created every time, rather than overwriting the old one. I'm tired, sorry for the poor explaination!


It's not the name - it's the depth that you're loading it at (2). Try replacing 2 with x and it should work for you:

ham_mc.onPress=function(){
startDrag(this);
}
ham_mc.onRelease=ham_mc.onReleaseOutside=function(){
stopDrag();
_root.ham_mc.duplicateMovieClip("ham_mc" + x ,x);
_root['ham_mc' + x]._x = 50;
_root['ham_mc' + x]._y = 50;
x++;
}

Loading clips at the same depth will always replace the clip previously loaded at that depth.

Edited and tested :)


Demian's answer is correct, but only if your x count matches the total number of MovieClips on the stage. Also, all clips are set to the same X and Y position. This should work better:

ham_mc.onPress=function(){
    startDrag(this);
}
ham_mc.onRelease=ham_mc.onReleaseOutside=function(){
    stopDrag();
    _root.ham_mc.duplicateMovieClip("ham_mc" + x ,_root.getNextHighestDepth());
    _root['ham_mc' + x]._x = _root._xmouse;
    _root['ham_mc' + x]._y = _root._ymouse;
    x++;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜