368
Working with Movie Clips
Determining the depth of an instance
To determine the depth of a movie clip instance, use
MovieClip.getDepth()
.
The following code iterates over all the movie clips on a SWF file’s main timeline and shows
each clip’s instance name and depth value in the Output panel:
for (var item:String in _root) {
var obj:Object = _root[item];
if (obj instanceof MovieClip) {
var objDepth:Number = obj.getDepth();
trace(obj._name + ":" + objDepth)
}
}
For more information, see
getDepth (MovieClip.getDepth method)
in the
ActionScript 2.0 Language Reference
.
Swapping movie clip depths
To swap the depths of two movie clips on the same timeline, use
MovieClip.swapDepths()
.
The following examples show how two movie clip instances can swap depths at runtime.
To swap movie clip depths:
1.
Create a new Flash document called
swap.fla
.
2.
Draw a blue circle on the Stage.
3.
Select the blue circle, and then select Modify > Convert to Symbol.
4.
Select the Movie clip option, and then click OK.
5.
Select the instance on the Stage, and then type
first_mc
into the Instance Name text box
in the Property inspector.
6.
Draw a red circle on the Stage, and then select Modify > Convert to Symbol.
7.
Select the Movie clip option, and then click OK.
8.
Select the instance on the Stage, and then type
second_mc
into the Instance Name text box
in the Property inspector.
9.
Drag the two instances so that they overlap slightly on the Stage.
10.
Select Frame 1 of the Timeline, and then type the following code into the Actions panel:
first_mc.onRelease = function() {
this.swapDepths(second_mc);
};
second_mc.onRelease = function() {
this.swapDepths(first_mc);
};
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...