MovieClip.swapDepths( ) Method

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
MovieClip.swapDepths( ) Method Flash 5

change the graphic layering of an instance in the visual content stack
mc.swapDepths(target) mc.swapDepths(depth)

Arguments

target

A string indicating the path to the movie clip to be swapped with mc. Because movie clip references are converted to paths when used in a string context, target can also be a movie clip object reference, as in mc.swapDepths(window2) versus mc.swapDepths("window2").

depth

An integer, between -16384 and 1048575 (inclusive), specifying a level in mc's parent's clip stack. Higher depths obscure lower depths, so a depth of 6 is in front of 5, which is in front of 4, and so on. Depths above -1 are reserved for dynamically generated content; depths from -16383 to -1 (inclusive) are reserved for author-time content; and depth -16384 is reserved for dynamic content that appears beneath all author-time content in mc (e.g., a runtime background). For important details, see Section 13.4.

Description

All movie clip instances in a .swf document reside in a stack that governs the visual layering of instances in the Player. The stack is structured like a deck of cards; clips in higher positions in the stack appear in front of clips in lower positions. The position of an instance in the stack is initialized when the clip is created (either in the Flash authoring tool or via attachMovie( ), duplicateMovieClip( ), or createEmptyMovieClip( )). Using swapDepths( ), we can change the position of an instance in the stack.

The swapDepths( ) method takes two forms. When used with a target argument, swapDepths( ) trades the stack position of mc and target, provided that mc and target share the same parent clip (i.e., they reside on the same timeline). When used with a depth argument, swapDepths( ) places mc in a new position in mc's parent stack. If that position is occupied, the previous occupant is moved to mc's old position. Note that swapDepths( ) cannot be used to move a clip outside of the stack maintained by its parent. For information on how movies and movie clips are stacked in the Player, see Section 13.4. To determine the current depth of a clip, use MovieClip.getDepth( ).

Bugs

Note that swapping a duplicated or attached instance with a manually created instance via the depth argument can cause redraw problems in Flash Player 5. Treat the depth argument with prudence, and always test depth-swapping code extensively.

See Also

MovieClip.attachMovie( ), MovieClip.createEmptyMovieClip( ),, MovieClip.createTextField( ), MovieClip.duplicateMovieClip( ), MovieClip.getDepth( ); Section 13.4



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net