ActionScript 2.0 Components Language Reference |
|
|
|
| DepthManager class > DepthManager.setDepthTo() | |||
Flash Player 6 (6.0.79.0).
Flash MX 2004.
movieClipInstance.setDepthTo(depthFlag)
depthFlag One of the following values: DepthManager.kTop, DepthManager.kBottom, DepthManager.kTopmost, DepthManager.kNotopmost. All depth flags are static properties of the DepthManger class. You must either reference the DepthManager package (for example, mx.managers.DepthManager.kTopmost) or use the import statement to import the DepthManager package.
Nothing.
Method; sets the depth of movieClipInstance to the value specified by depthFlag. This method moves an instance to another depth to make room for another object. DepthManager uses a "shuffling" algorithm to set the depths in increments of 20. The algorithm increments depths in case Flash needs to insert something else in the middle, based on other scripts, components, and so on.
The following example uses two components (or movie clips) to raise their depth alternately in increments of 20 as each one is clicked. First add a Button component to the Stage and give it instance name a_btn Then add another Button component to the Stage and give it instance name b_btn. Make sure the buttons overlap as follows:

import mx.managers.DepthManager;
a_btn.onRelease = function() {
b_btn.setDepthTo(DepthManager.kTop);
var b_depth:Number = b_btn.getDepth();
trace(b_depth);
}
b_btn.onRelease = function() {
a_btn.setDepthTo(DepthManager.kTop);
var a_depth:Number = a_btn.getDepth();
trace(a_depth);
}
Test the SWF file. When you click the top button, the other button changes depth and moves to the front, and the Output panel displays that button's depth. The values are 20, then 40, then 60, incremented by 20 each time you click.
|
NOTE |
If you use DepthManager with movie clip instances instead of component instances, you may need to add a UI component to your library (if one isn't already there) for DepthManager to operate properly. DepthManager requires a component on the Stage or in the library to function. |
For more information about depth and stacking order, see "Determining the next highest available depth" in Learning ActionScript 2.0 in Adobe Flash.
|
|
|
|