How to Understand Several Keywords
What do _root, _level and depth do? Many novices are confused by these key words. They can not get the meaning and function; furthermore, they are barred when referring to apply AS. Let’s get down to deep our understanding of these keywords right now.
Series: SWF Quicker 2.0
_level and path
Let’s talk something about the catalogue of this file before we begin this lesson. It is really similar to SWF file.
I have a mypath.txt saved in local internet, I put this file in a folder named AStarArithmetic, which belongs to download folder of C disc. So the path showing the specific direction of mypath.txt is: c:\downloads\AStarArithmetic\mypath.txt. Movie clip or other objects saved in SWF follow the same rule.
Continue with the analogy above. _level0, _level1 and _level2 can be compared to C, D and E discs. Downloads and AStarArithmetic just like two movie clips, and mypath.txt is the final movie clip. You can visit mypath.txt by using the specific path: _level.downloads.AStarArithmetic. Do you get it? Please notice that you can not name a movie clip as mypath.txt, I just take mypath.txt as an example.
_root can be compared to root. Continue with the analogy above: The root of c:\downloads\AStarArithmetic\mypath.txt is C disc. The root of any file in the C disc is C disc. Likewise, the root of any movie clip of _level0 is level0.
What is depth?
Depth is different from _level and _root. It is related to display order. The bigger the depth is, the upper it displays. The most important function of _level and _root is to identify the path of movie clip in SWF.
It is better to notice that _level has its default depth, and each movie clip has its depth to distribute. The depth value ranges from -16384 to 1048575.
Why each _level has its default depth?
That is because all _level including _level0, _level1, _level…belong to the higher catalogue-movie clip, which is SWF itself probably. _level0 lie in -16384 and _level1 lie in -16383. SWF may support about 955599999999 _level from deducing.
You can even switch the depth of _level0 and _level1 if you don’t want the default depth of them. Have a try.
I will give an example:
1. Open a new file.
2. Write loadMovieNum("dog.jpg",1); in frame one.
Enter a file name that is in your local internet, and then create a new layer and draw something in it. Make sure this layer lasts for 30 frames. In addition, the new loaded picture and the things you draw in the layer are overlapped, or you can not see the effect.
3. Write following scripts in frame 15:
4. Write following scripts in frame 30:
OK, you will find the things in _level0 are moved to _level1 when _level0 and depth 1 are switched. The result is as follows:
Is it a little bit interesting? Glad to share my thought with you!
Click root.rar (27.16 KB) to download the source file.
TIPS: Each level should include something, or you can not trace, for instance, the function trace (_level1.getDepth ()) is invalid if you don’t use function loadMovie to load something to _level1.
It is easy to understand the words mentioned-each movie clip has its depth to distribute. That means _level2 can have its depth if _level1 has its depth. There is no conflict between them. The display of them is decided by the depth.