You can create an instance at the topmost depth, but then swap them to a
target depth using something like setAtDepth...


function setAtDepth ( mc, depth )
{
        //      SET MC TO DEPTH
        //      -       will push all other instances down in depth if
conflicting

        // depths will be based on parent
        var p = mc._parent;

        // ERROR || NO PARENT
        if ( p == undefined ) return;

        // get instance currently at depth
        var instance = p.getInstanceAtDepth ( depth );

        // set out of the way to not disturb other mcs
        instance.swapDepths ( p.getNextHighestDepth() );

        // put into place
        mc.swapDepths ( depth );

        // push movieClips down till there are none left
        while ( instance != undefined )
        {
                // decrease the depths
                depth --;

                // get next instance
                var nInstance = p.getInstanceAtDepth ( depth );

                // swap depths
                instance.swapDepths ( depth );

                // set previous instance
                instance = nInstance;
        }
}




I came up with this little gem after finding a hack for removeMovieClip()'s
negative depth issue.




function safelyRemoveClip ( mc:MovieClip ):Void
{
        //      CLIPS ON THE TIMELINE USUALLY HAVE A NEGATIVE DEPTH AND ARE
NOT AFFECTED BY REMOVECLIP.
        //      THIS IS A QUICK HACK

        var mcTemp:MovieClip = mc._parent.getInstanceAtDepth(0);
        mc.swapDepths(0);
        mc.removeMovieClip();
        if(mcTemp != undefined)
        {
                mcTemp.swapDepths(0);
        }
}



_____________________________

Jesse Graupmann
www.jessegraupmann.com    
www.justgooddesign.com/blog/      
_____________________________



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Kannan
Bharadwaj
Sent: Tuesday, June 26, 2007 11:46 PM
To: flashcoders@chattyfig.figleaf.com
Subject: [Flashcoders] How can I keep some MovieClips always on top?

I need to maintain certain movieclips always on top. I have been using
getNextHighestDepth() in creating these movieclips. One option is to specify
the depth for these alone to be very close at the point of their creation.
However, am not sure if mixing getNextHighestDepth() for some MCs and hard
coding for some others is the best way to do this.

Appreciate if anyone can suggest a better way..

 

Thanks

Kannan

 

----------------------------------------------------------------------------
--------

Kannan Bharadwaj

SolutionSpace

Email: [EMAIL PROTECTED]

URL: www.solution-space.net

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to