Skip to main content
Participating Frequently
April 28, 2007
Answered

How does " bringToFront()" work?

  • April 28, 2007
  • 11 replies
  • 647 views
I have a movie clip in a game I am making, that replaces the mouse. I need it to be infront of everything else on the stage, and some things are attached from the library (so I can't controll their depth with layers anymore). I thought I had worked it out when I found the bringToFront(); function, but I don't think I am using it properly, because it doesn't turn blue like I thought it should, and it doesn't effect the depth of the movieclip. This is what i wrote:

var d = my_mc.bringToFront();

I would be greatful for any help. Thanks.
P
This topic has been closed for replies.
Correct answer dazzie7617784
The way I tend to do it is like this:-

aliendepthoffset = 1000;
numofaliens = 100;
alienxspacing = 18;
alienyspacing = 18;
numaliensinrow = 5;

for (i=0; i<numofaliens; i++) {
duplicateMovieClip(_root.alienclip , newname="myalien"+i, i + aliendepthoffset);
currentalien = eval("_root.myalien"+i);
currentalien._x = (i * alienxspacing) - (int(i/numaliensinrow)*( numaliensinrow*alienxspacing));
currentalien._y = int(i/numaliensinrow) * alienyspacing;
}



...whether that's particularly nice code or not, I'm sure there are better ways, but it gives you an idea of how I place them onto depth layers.

11 replies

einnepAuthor
Participating Frequently
May 11, 2007
Thanks for the help!
einnepAuthor
Participating Frequently
May 1, 2007
Thanks for all the great advice! I wonder if anyone would mind helping me with how the code should look for establishing the depths for the different "chuncks" or groups... how do I establish that? like this sort of thing: fallingGroup.depth = 1000-2000; and then have made fallingGroup an array before that, or... ?
dazzie7617784Correct answer
Inspiring
May 1, 2007
The way I tend to do it is like this:-

aliendepthoffset = 1000;
numofaliens = 100;
alienxspacing = 18;
alienyspacing = 18;
numaliensinrow = 5;

for (i=0; i<numofaliens; i++) {
duplicateMovieClip(_root.alienclip , newname="myalien"+i, i + aliendepthoffset);
currentalien = eval("_root.myalien"+i);
currentalien._x = (i * alienxspacing) - (int(i/numaliensinrow)*( numaliensinrow*alienxspacing));
currentalien._y = int(i/numaliensinrow) * alienyspacing;
}



...whether that's particularly nice code or not, I'm sure there are better ways, but it gives you an idea of how I place them onto depth layers.
Inspiring
May 1, 2007
You need to be carfeul using getNextHighestDepth() as it can result in movieclips that don't allow you to remove them (if the value from that function is ridiculously high - which it often is). I had this problem and was scratching my head for ages trying to work out what was going on!

You also need to remember that each clip has to have it's own depth (that may explain why your cursor disappeared after a short while if you were still creating movie clips and they hit the same depth?)

I tend to keep my depths in chunks ... so I reserve them in groups ... for example, if I was writing a game I might put the aliens on depths from 1000 to 2000, the player ship on layer 3000, bullets on 4000 to 5000 .... etc. That way I know what should be sitting above what and I don't have to keep swapping depths all the time. Depending on your application this may or may not be practical.
May 1, 2007
that will work.
April 30, 2007
why not have a two tier'd depth system, so instead of using getNextHighestDepth() have an incrementing variable _root.depth++ starting at 1 and then set anything you want to be on top like your fake cursor to depths over 1,000,000.
Saves hassling around with swapping depths everytime you need to add a new mc.
April 29, 2007
everytime you attach a new movie clip on the stage you have to swap depths
einnepAuthor
Participating Frequently
April 28, 2007
...is it possible that there is a function around that can just say " no matter what comes onto the stage, this MC should always be in front" ? I think it is dissapearing as the next object in the array is attached.
einnepAuthor
Participating Frequently
April 28, 2007
hi again. Super! it worked, and it was in front of the attached clips in the array that I attached -

...but then the mouse MC dissapears after a short time... hmmm, I wonder how that happened? too complicated?
April 28, 2007
sorry typo:
MyNewMovie.swapDepths(myCurserMC);
einnepAuthor
Participating Frequently
April 28, 2007
Thanks for the reply! Is swapthDepth a funciton or is there a typo there? I just tried it and doesn't turn blue either...