I have gone through the kirupa explanations about depths, and am trying to do something like the swapDepths example (with the green, yellow, and blue windows) included on this site. The three windows does just what I’m trying to do, but I can’t get swapDepths to do what I want it to in my project. Some of the differences I see between mine and the swapDepths example are:
- The movie clips in the example were created at author time; mine are created dynamically via attachMovie.
- The script code in the example is attached to each window. Since my movie clips are created at runtime, that is not possible. Instead, my code is in a function that is executed when onPress is activated on a given movie clip.
All my code is attached to Frame 1. The function below gets executed once via a call to it at the very beginning of the script:
[FONT=‘Courier New’]function initRoutine () {[/FONT]
[FONT=‘Courier New’] depthNew = new Number();[/FONT]
[FONT=‘Courier New’] for (var y = 0; y < 50; ++y) {[/FONT]
[FONT=‘Courier New’] mcName = “box.” + x[/FONT]
[FONT=‘Courier New’] mc = _root.attachMovie(libClip,mcName,depthMc++,);[/FONT]
[FONT=‘Courier New’] mc.onPress = prepForMove;[/FONT]
[FONT=‘Courier New’] }[/FONT]
[FONT=‘Courier New’]}[/FONT]
I’ve tried using an explicit value in swapDepths:
[FONT=‘Courier New’]function prepForMove () {[/FONT]
[FONT=‘Courier New’] this.swapDepths(depthNew++);[/FONT]
[FONT=‘Courier New’]}[/FONT]
And I’ve tried swapping with an empty movie clip that I create:
[FONT=‘Courier New’]function prepForMove () {[/FONT]
[FONT=‘Courier New’] newMc = “move”+depthNew;[/FONT]
[FONT=‘Courier New’] newMc = _root.createEmptyMovieClip(newMc,depthNew++);[/FONT]
[FONT=‘Courier New’] this.swapDepths(newMc);[/FONT]
[FONT=‘Courier New’]}[/FONT]
Through trace statements, I have verified that the parents of “this” and “newMc” are identical.
I can’t get the depths to be swapped with either method.