Hi, I understand how to swap depths of one movie clip with another, but what I need is to click on a movie clip and have that clip be sent to the back, or lowest level. Basically I will have four movieclips, what I want is to click on one clip and make that clip the background so the other three will play on top of it. I don’t want to have a whole mess of code, just something as simple as possible. Does anyone have any suggestions as to what the simplest way of doing this would be? Thank you.
Depending on what you’re doing, there are two ideal methods:
One would be to duplicate or re-attach the movie clip to the desired depth, then use removeMovieClip to get rid of the old one.
The second is more complicated, but should work better in the long run. If possible, get an array listing all the movie clips you want to sort (sort depths I mean). Then push the one clip in that array to the back. Run a for loop through the array swaping depths. To set up an example, create a movieClip with “p” as it’s linkage. Delete it from the stage (keep it in the library) and stick this in frame one:
clipsToSort = new Array();
for(i=0;i<10;i++){
c = attachMovie("p", "p"+i, i);
c._x = 50*i;
clipsToSort* = c;
}
_root.onMouseDown = function(){
for(i=clipsToSort.length;i>0;i--){
currentClip = clipsToSort*;
if(currentClip.hitTest(_xmouse, _ymouse, true)){
clipsToSort.splice(i, 1);
clipsToSort.push(currentClip);
fSort_depths();
i = 0;
}
}
}
function fSort_depths(){
}
}
It starts by attaching the movieClips and creating an array of them. Then whenever you click, it checks which one you’re targeting, and moves it’s position in the array; in this example, to the front usuing the push() function. When everythings in order, sort it.
I hope you can use one of these methods. Good luck! :elderly: