Groups | Blog | Home
all groups > flash actionscript > may 2005 >

flash actionscript : Changing stacking order with onRollOver


plasticonoband
5/2/2005 12:00:00 AM
I am trying to have the stacking order of several movie clips change with an
onRollOver. Each movie clip needs to appear on top when a rollover occures on
its corresponding button. I've been playing around with following code but
nothing is working. Can someone tell me if I'm on the right track? If not, can
you clue me in on how to do this?

Thanks in advance.

btn102.onRollOver = function():Void {
var nDepth:Number = mc102.getNextHighestDepth();
}


btn101.onRollOver = function():Void {
var nDepth:Number = mc101.getNextHighestDepth();
}

btn103.onRollOver = function():Void {
var nDepth:Number = mc103.getNextHighestDepth();
}
Mr Helpy mcHelpson
5/2/2005 12:00:00 AM
mx.behaviors.DepthControl.bringToFront(this.whatever_your_movie_clip_is);

this can be accessed from the behaviors panel, or written in like this!

Mr Helpy mcHelpson
5/2/2005 12:00:00 AM
plasticonoband
5/2/2005 12:00:00 AM
plasticonoband
5/2/2005 12:00:00 AM
David,

David Stiller
5/2/2005 3:19:19 PM
plasticonoband,

[quoted text, click to view]

Okay. You'll be happy ... this one isn't too hard.

[quoted text, click to view]

btn102.onRollOver = function():Void {
var nDepth:Number = mc102.getNextHighestDepth();
}

Assuming btn102 is either a button or movie clip, you have correctly
assigned a function to that instance's onRollOver event handler. So far, so
good. Whenever this instance is rolled over, a certain set of instructions
should occur. Let's see what you've told the function to do.

You have a single line of code inside the function. This line does the
following: it creates a variable of the Number datatype, which makes sense,
since we're dealing with depths, and depths are described as numbers. This
variable is being set to the value returned by
MovieClip.getNextHighestDepth() as invoked on a MovieClip instance (I
presume) with the instance name mc102. And then ... well, and then nothing.
;) Nothing is being done with this number. A variable is set to the number
returned, but to get it to *do* anything, you'll have to use something like
MovieClip.swapDepths() on the movie clip in question.


So if btn102 is supposed to make mc102 "rise to the top," you'll want to
do something like this:

btn102.onRollOver = function():Void {
mc102.swapDepths(_root.getNextHighestDepth());
}

Loop up MovieClip.swapDepths to see exactly what it does. You can
either use it to trade places with another movie clip or send a clip to a
given depth number.

Don't just copy and paste what I've typed, though: you have to
understand what I've suggested. The visual stacking of the movie clips in
question depend entirely on their organiziation. If these movie clips are
nested *inside* their namesake buttons, swapthDepths() will only move them
up inside the buttons that house them -- it won't move them higher than each
other (does that make sense?).

If the movie clips are all on the main timeline, then you'll want to use
the _root (as a suggestion) to be your basis for the number
getNextHighestDepth() returns.

You have to give that method a point of view. The way you've written
your code, it looks as if each movie clip lies inside a button. The reason
I say this is because you haven't provided paths to any of the clips. From
btn102's point of view -- which is how its onRollOver function sees
things -- mc102 must be nested immediately inside it. If it was in the same
timeline as the button, it would be "one step up" from *inside* the button,
which means you might put _parent.mc102 as your path to mc102.

Give it a shot and come back if you need additional help. :)


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

David Stiller
5/2/2005 3:30:53 PM
[quoted text, click to view]

Interesting. :) I never think to look at the Behaviors.

Looking at DepthControl now, I see its bringToFront() method basically
just uses MovieClip.swapDepths(), but having the convenience wrapper is
nice.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

David Stiller
5/2/2005 4:05:16 PM
plasticonoband,

[quoted text, click to view]

I go back and forth on the use of Behaviors in general. On principle, I
prefer to write my own code, but then, I'm comfortable with ActionScript.
Having said that, I'll be quick to mention I certainly use UI Components and
regularly use built-in classes -- dependent mostly on how much time it will
save me to use the pre-build solution.

For something like swapping depths, I would probably continue to use
MovieClip.swapDepths() -- but that's me -- and heck, as I replied earlier,
it's nice to know there's a DepthControl class out of the box. It often
helps to "see how Macromedia did it," and most of these convenience wrappers
are available in the Classes folder in side the Flash MX 2004 folder.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

plasticonoband
5/3/2005 12:00:00 AM
Okay, this has turned out to be a little harder than I thought. To test both
of these methods, I created a small test flash application and each one worked
really well. I really need to get this to work on a large application I've
been working on, and now I run into problems with both methods.

The "bring to front" behavior works but it is loading way too slow so I can't
use it. I think the reason it is running too slow is because I'm using a
scrollpane. The buttons exist in a scrollpane and they need to affect objects
outside of the scrollpane (in the main movie). I'm also using screens which may
be part of the problem.

Anyway, when I try David's actionscript method I think I'm running into path
problems. Since I'm using the scrollpane I've been using the path
"_root.application.southBuilding.mcFloor1_s" in other situations where I need
to point to the screen that holds the scrollpane. I assumed I would use this
path in the swapDepths script. Here is what I've been trying.

btFlr1_s_103.onRollOver = function():Void {

rm103.swapDepths(_root.application.southBuilding.mcFloor1_s.getNextHighestDepth
());
}

btFlr1_s_104.onRollOver = function():Void {

rm104.swapDepths(_root.application.southBuilding.mcFloor1_s.getNextHighestDepth
());
}

btFlr1_s_105.onRollOver = function():Void {

rm105.swapDepths(_root.application.southBuilding.mcFloor1_s.getNextHighestDepth
());
}


the buttons with the rollOver exist in the scrollpane. The rm10_ instances
are in the screen that contains the scrollpane. I have to go all the way back
to "_root" and then back up since the scrollpane is made up of a completely
separate movieClip. The path has worked for the other situations pointing from
the scrollpane to its main screen.

I hope this all makes sense. If anyone can see what I'm doing wrong, I'd
appreciate an explanation.
AddThis Social Bookmark Button