# Depth Sorting Issue - How to make MC always on "top"?

**URL:** <https://forum.kirupa.com/t/depth-sorting-issue-how-to-make-mc-always-on-top/281345>\
**Category:** flash\
**Created:** [February 8, 2009, 2:41am UTC](https://forum.kirupa.com/t/depth-sorting-issue-how-to-make-mc-always-on-top/281345 "2009-02-08T02:41:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mileskemp](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@mileskemp](https://forum.kirupa.com/u/mileskemp)\
**Post date:** [February 8, 2009, 2:41am UTC](https://forum.kirupa.com/t/depth-sorting-issue-how-to-make-mc-always-on-top/281345/1 "2009-02-08T02:41:15Z")

</div>

Hey guys,  
I just can figure out how to make my navigation mc (named navBAR) always stay on the top layer, highest depth. Everytime the slideshow image reloads, when the navBAR is showing, it immediately becomes not visible.

Is there anyway to make it so that navBAR is on the top level even if the slideshow is building progessive layers behind?

Any help is much appreciated. You rule!

M

My code:

stop();  
//  
Stage.scaleMode = “noScale”;  
Stage.align = “TL”;  
//  
import mx.transitions.Tween;  
import flash.display.BitmapData;  
//  
var root:MovieClip = this;  
var totalItems:Number = imgArray.length;  
var autoStart:String = s\_autoStart;  
var imageScale:String = s\_imageScale;  
var mvSec:Number = s\_slideSpeed;  
var mvEase:Object = mx.transitions.easing.Regular.easeOut;  
var totalRounds:Number = 5_1000/50;  
var timerInc:Number = 100/totalRounds;  
var leftrightgap:Number = 100;  
var gapinmyCP:Number = 6;  
var curImage:Number = 0;  
//---------------------------------------------------  
//stage resize function  
//---------------------------------------------------  
var listner:Object = new Object();  
listner.onResize = function() {  
sh = Stage.height;  
sw = Stage.width;  
//  
//navBAR resizers  
root.navBAR.navRollover.\_width = sw;  
root.navBAR.greynav.\_width = sw;  
root.navBAR.greysubnav.\_width = sw;  
root.navBAR.d\_hitArea.\_width = sw;  
root.navBAR.navFADEIN.\_width = sw;  
root.navBAR.navFADEIN.\_height = sh+sh+sh+sh;  
root.navBAR.navFADEIN.\_y = -sh-sh;  
//  
//control panel resizers  
root.myCP.\_y = sh-root.myCP.t\_bg11.\_height;  
root.myCP.t\_bg11.\_width = root.myCP.t\_bg.\_width=root.myCP.t\_hitArea.\_width=root.myCP.about\_page.a\_bg.\_width = sw;  
root.myCP.t\_bg.\_x = root.myCP.t\_bg2.\_x=root.myCP.t\_hitArea.\_x=0;  
root.myCP.t\_copy.\_x = sw-root.myCP.t\_copy.\_width-gapinmyCP;  
root.myCP.t\_timer.\_x = gapinmyCP+root.myCP.t\_stop.\_width-10;  
root.myCP.t\_play.\_x = root.myCP.t\_stop.\_x=gapinmyCP;  
root.myCP.t\_hol.\_x = gapinmyCP+root.myCP.t\_stop.\_width+root.myCP.t\_timer.\_width;  
root.myCP.t\_hol.t\_mask.\_width = 300;  
root.myCP.d\_head.\_x = sw-root.myCP.d\_head.\_width-gapinmyCP;  
//  
if (root.myCP.t\_hol.t\_mask.\_width\>root.totalbtnwidth) {  
root.myCP.t\_hol.buttonsbg.\_width = root.totalbtnwidth;  
} else {  
root.myCP.t\_hol.buttonsbg.\_width = root.myCP.t\_hol.t\_mask.\_width;  
}  
root.lil\_img.\_y = root.myCP.\_y-root.lil\_img.\_height;  
//  
root.max = root.myCP.t\_hol.t\_mask.\_width;  
root.myCP.t\_hol.buttonsbg.onRollOver = root.moveLilImg;  
var tbg:Tween = new Tween(root.myCP.t\_hol.buttons, “\_x”, root.mvEase, root.myCP.t\_hol.buttons.\_x, 0, root.mvSec, true);  
//  
//image resizers  
if (root.imageScale == “true”) {  
if (sw\>1000 or sh\>600) {  
imageHolderDone.\_width = sw;  
imageHolderDone.\_yscale = imageHolderDone.\_xscale;  
}  
//  
if (sw\>1000) {  
if (imageHolderDone.\_width\<sw) {  
imageHolderDone.\_width = sw;  
imageHolderDone.\_yscale = imageHolderDone.\_xscale;  
}  
}  
if (sh\>600) {  
if (imageHolderDone.\_height\<sh) {  
imageHolderDone.\_height = sh;  
imageHolderDone.\_xscale = imageHolderDone.\_yscale;  
}  
}  
}  
//  
imageHolderDone.\_x = sw/2-root.imageHolderDone.\_width/2;  
imageHolderDone.\_y = sh/2-root.imageHolderDone.\_height/2;  
//  
//preloader resizer  
myCP.t\_preloader.\_x = 0;  
myBarBgWidth = sw;  
myCP.t\_preloader.\_width = myPercent_myBarBgWidth/100;  
//  
//main img preloader  
root.mainpre.\_x = sw/2;  
root.mainpre.\_y = sh/2;  
//  
//info panel pos  
navBAR.\_x = sw-sw;  
infoDestY = Math.round(sh-200);  
var inf:Tween = new Tween(root.navBAR, “\_y”, root.mvEase, root.navBAR.\_y, infoDestY, root.mvSec, true);  
};  
Stage.addListener(listner);  
//---------------------------------------------------  
//mouse wheel function function  
//---------------------------------------------------  
var mouseListener:Object = new Object();  
mouseListener.onMouseWheel = function(delta) {  
root.myCP.t\_hol.buttons[“b”+root.curImage].gotoAndPlay(“out”);  
if (delta == 3) {  
if (root.curImage\<root.totalItems-1) {  
root.curImage = root.curImage+1;  
} else {  
root.curImage = 0;  
}  
} else {  
if (root.curImage\>0) {  
root.curImage = root.curImage-1;  
} else {  
root.curImage = root.totalItems-1;  
}  
}  
root.showImage(root.curImage);  
};  
Mouse.addListener(mouseListener);  
//---------------------------------------------------  
//button’s function  
//---------------------------------------------------  
rollIn = function () {  
var trg:MovieClip = root.lil\_img.t\_img;  
var dest:Number = -(this.no\*(root.s\_thumbWidth+5)-5);  
var myTween:Tween = new Tween(trg, “\_x”, root.mvEase, trg.\_x, dest, root.mvSec, true);  
//  
if (root.curImage != this.no) {  
this.gotoAndPlay(“in”);  
}  
};  
rollOt = function () {  
if (root.curImage != this.no) {  
this.gotoAndPlay(“out”);  
}  
};  
root.myCP.about\_page.a\_btn.onRollOver = root.myCP.t\_play.onRollOver = root.myCP.t\_stop.onRollOver=root.myCP.t\_fs.onRollOver=function () {  
this.gotoAndPlay(“in”);  
};  
root.myCP.about\_page.a\_btn.onRollOut = root.myCP.t\_play.onRollOut = root.myCP.t\_stop.onRollOut=root.myCP.t\_fs.onRollOut=function () {  
this.gotoAndPlay(“out”);  
};  
root.myCP.t\_play.onRelease = root.myCP.t\_play.onReleaseOutside=function () {  
this.gotoAndPlay(“out”);  
root.startTimer();  
root.autoStart = “true”;  
this.\_visible = false;  
this.\_parent.t\_stop.\_visible = true;  
};

root.abtOn = “false”;  
root.myCP.about\_page.a\_btn.onRelease = function(){  
showAbout();  
}  
root.myCP.t\_stop.onRelease = root.myCP.t\_stop.onReleaseOutside=function () {  
this.gotoAndPlay(“out”);  
if (root.timerId) {  
this.\_parent.t\_timer.bar.\_width = 1;  
root.stopTimer();  
}  
root.autoStart = “false”;  
this.\_visible = false;  
this.\_parent.t\_play.\_visible = true;  
};  
if (root.autoStart == “true”) {  
root.myCP.t\_play.\_visible = false;  
} else {  
root.myCP.t\_stop.\_visible = false;  
}  
//  
//---------------------------------------------------  
//main functions  
//---------------------------------------------------  
showAbout = function(){  
if(root.abtOn == “false”){  
var showAbt = new Tween(root.myCP.about\_page, “\_y”, root.mvEase, root.myCP.about\_page.\_y, -(root.myCP.about\_page.a\_bg.\_height), root.mvSec, true);  
root.abtOn = “true”;  
}else{  
var showAbt = new Tween(root.myCP.about\_page, “\_y”, root.mvEase, root.myCP.about\_page.\_y, 0, root.mvSec, true);  
root.abtOn = “false”;  
}  
}  
showImage = function (goto:Number) {  
root.mainpre.\_visible = false;  
//stop running timer  
stopTimer();  
trace(root.myCP.t\_hol.buttons[“b”+root.curImage]);  
//if none, set 0 as 1st image;  
if (goto != undefined) {  
this = root.myCP.t\_hol.buttons[“b”+goto];  
} else {  
//unhiglight prev btn  
root.myCP.t\_hol.buttons[“b”+root.curImage].gotoAndPlay(“out”);  
}  
//set cur image  
root.curImage = this.no;  
//load image  
myLoader.loadClip(imgArray[root.curImage][0], root.imageHolder);  
//set cur image info  
root.myCP.t\_hol.buttons[“b”+root.curImage].gotoAndPlay(“in”);  
//  
};  
showControls = function () {  
var showC = new Tween(root.myCP, “\_y”, root.mvEase, root.myCP.\_y, Stage.height-root.myCP.t\_hitArea.\_height, root.mvSec, true);  
delete this.onRollOver;  
this.onEnterFrame = function() {  
if (this.hitTest(\_root.\_xmouse, \_root.\_ymouse, false)) {  
} else {  
delete this.onEnterFrame;  
root.myCP.t\_hitArea.onRollOver = showControls;  
var showC = new Tween(root.myCP, “\_y”, root.mvEase, root.myCP.\_y, Stage.height-root.myCP.t\_bg11.\_height, root.mvSec, true);  
}  
};  
};  
root.myCP.t\_hitArea.onRollOver = showControls;  
//  
showInfo = function () {  
var showI = new Tween(root.navBAR, “\_alpha”, root.mvEase, root.navBAR.\_alpha, 100, root.mvSec, true);  
delete this.onRollOver;  
this.onEnterFrame = function() {  
if (this.hitTest(\_root.\_xmouse, \_root.\_ymouse, false)) {  
} else {  
delete this.onEnterFrame;  
root.navBAR.d\_hitArea.onRollOver = showInfo;  
var showI = new Tween(root.navBAR, “\_alpha”, root.mvEase, root.navBAR.\_alpha, 0, root.mvSec, true);  
}  
};  
};  
root.navBAR.d\_hitArea.onRollOver = showInfo;  
//  
moveLilImg = function () {  
var tg2:MovieClip = root.myCP.t\_hol.buttons;  
var tg:MovieClip = root.lil\_img;  
var myTween:Tween = new Tween(tg, “\_alpha”, root.mvEase, tg.\_alpha, 100, 1.2, true);  
//  
delete this.onRollOver;  
if (tg2.\_width\>root.max) {  
var leng:Number = Math.abs(tg2.\_width-root.max);  
this.onEnterFrame = function() {  
if (this.hitTest(\_root.\_xmouse, \_root.\_ymouse)) {  
ms = this.\_parent.\_xmouse;  
stagecur = ms/root.max_100;  
tg2.\_x = -(Math.ceil(stagecur/100_leng));  
//  
var dest:Number = \_root.\_xmouse-root.lil\_img.t\_bg.\_width/2;  
tg.\_x += (dest-tg.\_x)/4;  
} else {  
this.onRollOver = root.moveLilImg;  
var myTween0:Tween = new Tween(tg, “\_alpha”, root.mvEase, tg.\_alpha, 0, 0.2, true);  
var myTween1:Tween = new Tween(tg, “\_x”, root.mvEase, tg.\_x, \_root.\_xmouse-100, 0.2, true);  
delete this.onEnterFrame;  
}  
};  
} else {  
this.onEnterFrame = function() {  
if (this.hitTest(\_root.\_xmouse, \_root.\_ymouse)) {  
var dest:Number = \_root.\_xmouse-root.lil\_img.t\_bg.\_width/2;  
tg.\_x += (dest-tg.\_x)/4;  
} else {  
this.onRollOver = root.moveLilImg;  
var myTween0:Tween = new Tween(tg, “\_alpha”, root.mvEase, tg.\_alpha, 0, 0.2, true);  
var myTween1:Tween = new Tween(tg, “\_x”, root.mvEase, tg.\_x, \_root.\_xmouse-100, 0.2, true);  
delete this.onEnterFrame;  
}  
};  
}  
};  
//---------------------------------------------------  
//countdown function  
//---------------------------------------------------  
tickTock = function () {  
root.myCP.t\_timer.bar.\_width += timerInc;  
if (\_root.secinc\<totalRounds) {  
\_root.secinc++;  
} else {  
clearInterval(root.timerId);  
//  
var m11:MovieClip = root.myCP.t\_hol.buttons[“b”+root.curImage];  
m11.gotoAndPlay(“out”);  
//  
if (root.curImage\<totalItems-1) {  
root.curImage++;  
} else {  
root.curImage = 0;  
}  
//  
var m1:MovieClip = root.myCP.t\_hol.buttons[“b”+root.curImage];  
m1.gotoAndPlay(“in”);  
//  
var myTween2:Tween = new Tween(root.myCP.t\_timer.bar, “\_width”, root.mvEase, root.myCP.t\_timer.bar.\_width, 1, root.mvSec, true);  
myLoader.loadClip(imgArray[root.curImage][0], imageHolder);  
}  
};  
stopTimer = function () {  
var myTweenSS:Tween = new Tween(root.myCP.t\_timer.bar, “\_width”, root.mvEase, root.myCP.t\_timer.bar.\_width, 1, root.mvSec, true);  
//trace(“clear”);  
clearInterval(root.timerId);  
delete root.timerId;  
};  
startTimer = function () {  
clearInterval(root.timerId);  
\_root.secinc = 0;  
root.timerId = setInterval(root, “tickTock”, 35);  
};  
//  
//---------------------------------------------------  
//movieClip loader functions  
//---------------------------------------------------  
var myLoader:MovieClipLoader = new MovieClipLoader();  
var listener:Object = new Object();  
listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {  
myLoaded = Math.round(bytesLoaded);  
myTotal = Math.round(bytesTotal);  
myPercent = Math.round(myLoaded/myTotal_100);  
if (target == root.imageHolder) {  
myCP.t\_preloader.\_alpha = 100;  
myCP.t\_preloader.\_width = myPercent_myBarBgWidth/100;  
}  
root.mainpre.\_x = Stage.width/2;  
root.mainpre.\_y = Stage.height/2;  
};  
listener.onLoadStart = function(target:MovieClip):Void {  
if (target == root.imageHolder) {  
root.mainpre.\_visible = true;  
//  
root.navBAR.\_alpha = 30;  
root.navBAR.d\_hitArea.enabled = false;  
//  
var stgp:MovieClip = root[“pre”];  
var t\_mhol1:Tween = new Tween(root.imageHolderDone, “\_alpha”, root.mvEase, root.imageHolderDone.\_alpha, 50, root.mvSec, true);  
var t\_pre2:Tween = new Tween(mcp, “\_alpha”, root.mvEase, mcp.\_alpha, 100, root.mvSec, true);  
} else {  
var mcp:MovieClip = target.\_parent[“pre”];  
var t\_pre2:Tween = new Tween(mcp, “\_alpha”, root.mvEase, mcp.\_alpha, 100, root.mvSec, true);  
}  
};  
listener.onLoadInit = function(target:MovieClip):Void {

```
if (target == root.imageHolder) {
    root.mainpre._visible = false;
    //
    myCP.t_preloader._alpha = 0;
    //
    bmp = new BitmapData(target.getBounds().xMax, target.getBounds().yMax, true, 0);
    bmp.draw(target);
    root.imageHolderDone.attachBitmap(bmp, 1);
    //
    root.imageHolderDone._alpha = 0;
    if (root.imageScale == "true") {
        root.imageHolderDone._width = Stage.width;
        root.imageHolderDone._yscale = root.imageHolderDone._xscale;
    }
    root.imageHolderDone._x = Stage.width/2-root.imageHolderDone._width/2;
    root.imageHolderDone._y = Stage.height/2-root.imageHolderDone._height/2;
    //
    var t_mhol2:Tween = new Tween(root.imageHolderDone, "_alpha", root.mvEase, root.imageHolderDone._alpha, 100, root.mvSec, true);
    var t_mhol3:Tween = new Tween(root.imageHolder, "_alpha", root.mvEase, root.imageHolder._alpha, 0, root.mvSec, true);
    var t_mpre:Tween = new Tween(root.myCP.t_preloader, "_width", root.mvEase, root.myCP.t_preloader._width, 1, root.mvSec, true);
    if (root.autoStart == "true") {
        startTimer();
    }
    //    
    if (imgArray[root.curImage][2] == null && imgArray[root.curImage][3] == null) {
        root.navBAR._alpha = 100;
        root.navBAR.d_hitArea.enabled = false;
        root.myCP.d_head.text = "Untitled";
        root.myCP.d_desc.text = "No info available";
        //
    } else if (imgArray[root.curImage][2] or imgArray[root.curImage][3]) {
        root.navBAR._alpha = 0;
        root.navBAR.d_hitArea.enabled = true;
        //
        if (imgArray[root.curImage][2] != undefined) {
            root.myCP.d_head.text = imgArray[root.curImage][2];
        }else{
            root.myCP.d_head.text = "Untitled";
        }
        if (imgArray[root.curImage][3] != undefined) {
            root.myCP.d_desc.text = imgArray[root.curImage][3];
        }else{
            root.myCP.d_desc.text = "No info available";
        }
    }
        root.myCP.d_head.autoSize = true;
        root.myCP.d_desc.autoSize = true;
        root.myCP.d_desc._y = root.myCP.d_head._y + root.myCP.d_head._height;
        root.navBAR.d_bg._height = root.myCP.d_head._height+root.myCP.d_desc._height;
        root.navBAR.d_foot._y = root.navBAR.d_bg._y+root.navBAR.d_bg._height;
        //    
} else {
    var mcp:MovieClip = target._parent["pre"];
    var t_pre:Tween = new Tween(mcp, "_alpha", root.mvEase, mcp._alpha, 0, root.mvSec, true);
    var t_pre1:Tween = new Tween(mcp, "_xscale", root.mvEase, mcp._xscale, 0, root.mvSec, true);
    var t_pre2:Tween = new Tween(mcp, "_yscale", root.mvEase, mcp._yscale, 0, root.mvSec, true);
    //remove preloader mc when finished
    t_pre.onMotionFinished = function() {
        removeMovieClip(mcp);
        //trace("KILL: " + mcp);
    };
}

```

};  
myLoader.addListener(listener);  
//  
//---------------------------------------------------  
//initiate  
//---------------------------------------------------  
var image:MovieClip = root.createEmptyMovieClip(“image”, root.getNextHighestDepth());  
var imageHolder:MovieClip = image.createEmptyMovieClip(“imageHolder”, image.getNextHighestDepth());  
var imageHolderDone:MovieClip = image.createEmptyMovieClip(“imageHolderDone”, image.getNextHighestDepth());  
var mainpre:MovieClip = root.attachMovie(“pre”, “mainpre”, root.getNextHighestDepth());  
trace("mainpre: "+mainpre);  
var buttons:MovieClip = root.myCP.t\_hol.createEmptyMovieClip(“buttons”, root.myCP.t\_hol.getNextHighestDepth());  
var mask:MovieClip = root.myCP.t\_hol.attachMovie(“mask”, “t\_mask”, root.myCP.t\_hol.getNextHighestDepth());  
mask.cacheAsBitmap = true;  
buttons.cacheAsBitmap = true;  
buttons.setMask(mask);  
root.myCP.swapDepths(root.getNextHighestDepth());  
root.lil\_img.swapDepths(root.getNextHighestDepth());  
root.navBAR.swapDepths(root.getNextHighestDepth());  
root.imageHolder.\_alpha = 0;  
root.imageHolderDone.\_alpha = 0;  
//  
root.lil\_img.t\_img.\_x = root.lil\_img.t\_msk.\_x=5;  
root.lil\_img.t\_img.\_y = root.lil\_img.t\_msk.\_y=5;  
root.lil\_img.t\_msk.\_width = root.s\_thumbWidth;  
root.lil\_img.t\_msk.\_height = root.s\_thumbHeight;  
root.lil\_img.t\_bg.\_width = root.s\_thumbWidth+9;  
root.lil\_img.t\_bg.\_height = root.s\_thumbHeight+10;  
root.lil\_img.t\_pointer.\_y = root.lil\_img.t\_bg.\_y+root.lil\_img.t\_bg.\_height;  
root.lil\_img.t\_pointer.\_x = root.s\_thumbWidth/2;  
root.lil\_img.\_alpha = 0;  
//  
for (i=0; i\<totalItems; i++) {  
var th:MovieClip = root.lil\_img.t\_img.createEmptyMovieClip(“t”+i, root.lil\_img.t\_img.getNextHighestDepth());  
var img:MovieClip = th.createEmptyMovieClip(“img”, th.getNextHighestDepth());  
var pre:MovieClip = th.attachMovie(“pre”, “pre”, th.getNextHighestDepth());  
[//img.loadMovie](https://img.loadMovie)(root.imgArray\*[1]);  
//trace(img);  
myLoader.loadClip(root.imgArray\*[1], img);  
th.\_x = (root.s\_thumbWidth+5)\*i;  
pre.\_x = (root.s\_thumbWidth+5)/2;  
pre.\_y = (th.\_y+root.s\_thumbHeight)/2;  
pre.\_alpha = 0;  
//  
var b:MovieClip = buttons.attachMovie(“button”, “b”+i, buttons.getNextHighestDepth());  
if (i\<9) {  
b.txt.text = “0”+(i+1);  
} else {  
b.txt.text = i+1;  
}  
b.\_x = (b.\_width+gapinmyCP)\*i;  
b.no = i;  
b.onRollOver = rollIn;  
b.onRollOut = b.onReleaseOutside=rollOt;  
b.onRelease = showImage;  
}  
root.totalbtnwidth = b.\_x+b.\_width;  
root.myCP.t\_hol.attachMovie(“inv”, “buttonsbg”, buttons.getNextHighestDepth());  
root.myCP.t\_hol.buttonsbg.onRollOver = moveLilImg;  
root.myCP.t\_hol.buttonsbg.\_y -= root.myCP.t\_hol.\_y-root.myCP.t\_bg11.\_height;  
root.myCP.t\_hol.buttonsbg.\_height = root.myCP.t\_bg.\_height;  
root.myCP.t\_hol.buttonsbg.\_width = root.totalbtnwidth;  
root.myCP.t\_hol.buttonsbg.\_alpha = 0;  
//  
showImage(root.curImage);  
listner.onResize();
