Using Swapdepth in a DoubleDragon-like sidescroller

Greetings everyone!

My friend and I are making a Double Dragon lookalike sidescroller with 2 players. I have uploaded an early version of the game to my site, go have a look. Player controls are: player1: arrow keys & player2: wasd.

www.theisjacobsen.dk/game

Now, what I’m looking for is a way to swap the depth of the characters when they pass each others on the y axis. I guess I could just check the y position of each of the tewo players each frame and adapt this code:

myMC1_mc.onRelease = function() {
this.swapDepths(myMC2_mc);
};
myMC2_mc.onRelease = function() {
this.swapDepths(myMC1_mc);
};

…to check which one of the players have the lowest y value and do a swapDepths on the players.

Now the problem: what do I do when time comes and we are ready to implement enemies in the game? All I could think of was that I would have to check the y pos of all actors on the scene every frame and place them in the correct stacking order using swapDepths in some way… But how to do it or if there is a better way of doing it I don’t know.

Does any of you know how to do that?