MovieClip Class getDepth replacement
DIGG IT!
2
Comments
Published
Friday, November 19, 2004
at
11:46 AM
.
When you are working with MovieClip depth, I have found this getDepth replacement method invaluable. It allows you to obtain depth information about children through the getDepth method when called on a parent MovieClip.&
GetDepth Example
First a little code as an example:
//get a reference to the child MovieClip on "top"
myTopRef = _level0.getDepth('top').ref
//get a reference to the child MovieClip on "bottom"
myBotRef = myTopRef = _level0.getDepth('bottom').ref
//get information on all child MovieClips
myDepthData = _level0.getDepth('all')
The method provides backward compatibility so it will not effect your existing movies that depend on getDepth. It works well with V1 and V2 components and lets you see what really exists within a MovieClip.
One of the dilemmas in working with MovieClips is that you can't assume that references are child MovieClips, they might point to another timeline in the player. This method used the sort order of the for .. in loop to sort between the two.
The getDepths replacement returns an object for each MovieClip. When you use 'top' or 'bottom', you will get a single object like so:
{depth:23, name:bob, ref:_level0.bob}
When you use 'all' you will get an array that contains all the child MovieClip objects within a parent MovieClip and references within the parent will be excluded. Here is a sample of what is returned:
[{depth:23, name:one, ref:_level0.one},{depth:24, name:two, ref:_level0.two},{depth:25, name:three, ref:_level0.three}]
Cheers,
Ted ;)

Hi Ted,
Nice one -- very useful! :) [Nit-pick mode]Would love to see constants in place of strings eg. getDepth.TOP and/or ideally an iterator... umm, ok, I didn't say that... we have for...in in AS after all![/Nit-pick mode]
Aral
I wanted this to be as simple as possible regarding the arguments, using Strings was low hanging fruit at the time. Feel free to make changes as needed.
Cheers,
ted ;)