Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the depth

Status
Not open for further replies.

XLax

Technical User
May 22, 2006
25
CA
I want three movie clips with variable Z in them to change depths according to their Z value.
IOW: the one with the highest z would go in front, lowest would go behind them.
How do I do this?

Alex -
Kawamoto fan
 
Okay fine. It's done

_____
Alex
 
What do I do..

onClipEvent(enterFrame){
swapDepth(Z);
}

(where Z is my depth variable)
Like that?

_____
Alex
 
I tried that way and it seems to not work too well. The clips kept flashing. I suppose I could've make it set a variable right after the swap so that it doesn't swap back but I only thought of that after I tried this:

onClipEvent (enterFrame) {
movieClip1.swapDepths(movieClip1.Z);
movieClip2.swapDepths(movieClip2.Z);
movieClip3.swapDepths(movieClip3.Z);
}

And it's working super well for me
For the record, I didn't write it.

_____
Alex
 
As long as it's working now I'm happy as... a leprechaun? (i unno)

Finished script placed on the movie clip containing the clips that change in depth:

onClipEvent (enterFrame) {
movieClip1.swapDepths(movieClip1.Z);
movieClip2.swapDepths(movieClip2.Z);
movieClip3.swapDepths(movieClip3.Z);
}



_____
Alex
 
You can do like this as well (but "if it's not broke don't fix it" by all means!)

[tt]//
onClipEvent (enterFrame) {
for (var i = 1; i<=3; i++) {
var mc = this["movieClip"+i];
if (mc.getDepth() != mc.z) {
mc.swapDepths(mc.z);
}
}
}
//[/tt]

Kenneth Kawamoto
 
I actually considered writing that nearly exact same script. Unfortunately I realised that my movie clips were all differently named.
I'd have to make 'i' detect a variable in an array to be the name of the next clip to be tested and it would get too confusing and complicated lol

_____
Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top