Flash ActionScript 3 Tutorial:
Change Depth of Objects on Stage
Even all objects had been loaded to the stage, the depth the objects can still be changed. The secret is:setChildIndex(Object_Name, depth)
Flash Tutorial Content:
Sometimes you wish to change the depth of objects on the stage, this can create some interesting animation effect. This Flash ActionScript tutorial shows you how to change the depth of objects on the stage.
The complete Flash Movie is shown as above, you may try how it works before you start this Flash ActionScript tutorial.
Flash ActionScript Codes:
/*
Preparation: Create Linkage for the MovieClip
STEP 1: Prepare MovieClips
You already prepared three MovieClips in the library
In this example, the name of the MovieClips are:
- Tree
- Sun
STEP 2: Create Linkage
Select the movieclip from the library window
Select "Linkage..." from the pop up window
The Linkage Properties window appear
Check the "Export for ActionScript"
Enter Name in the Class field
In this example, we used "Tree" and "Sun" for the class name
*/
//Set the Apple RadioButton to be selected by default
sun_rb.selected = true;
//Declare the Radio group (belong to same group)
//This can be done by using the first RadioButton (apple_rb)
var myRadioGroup:Object = tree_rb.group;
enter_btn.addEventListener(MouseEvent.CLICK, changeDepth);
function changeDepth(evt:MouseEvent):void {
// so that the Tree is behind the Sun
setChildIndex(myMovieClip1, 0);
// Display message
output_txt.text = "The depth of Tree is set to ZERO. Therefore the Tree will be put behind the Sun.";
// so that the Tree is behind the Sun
setChildIndex(myMovieClip2, 0);
// Display message
output_txt.text = "The depth of Sun is set to ZERO. Therefore the Sun will be put behind the Tree.";
}
Download Flash Source File:
Remarks:
This Flash ActionScript tutorial show how to change the depth of object on the stage of Flash Movie..