all groups > flash actionscript > september 2007 >
You're in the

flash actionscript

group:

HELP - serious swapDepths() bug



HELP - serious swapDepths() bug crazygringo
9/14/2007 8:45:05 PM
flash actionscript: Hi,

I'm trying to create a basic "windowing" setup in a Flash app. I have lots of
separate "window" symbols, and when I click on each one I want it to come to
the front, overlapping other windows.

So I write something like

myWindow.onPress = function() {
if (this.getDepth() != this._parent.getNextHighestDepth() - 1) {
this.swapDepths(this._parent.getNextHighestDepth() - 1);
}}

If there are only two or three windows it works. But if there are four or
five, then sometimes the window I click on doesn't rise to the top--*another*
window rises to the top.

I discovered I could get a partial workaround by looping:

myWindow.onPress = function() {
while (this.getDepth() != this._parent.getNextHighestDepth() - 1) {
this.swapDepths(this._parent.getNextHighestDepth() );
}}

Note, crucially, there is no "- 1" on the second getNextHighestDepth(). If I
keep it, the program hangs. But if I always increment the depth, then
*eventually* the window I click on makes it to the top, even if it has to loop
a couple of times.

Unfortunately, it messes up the order of other windows on the way.

This seems to me to be a clear, strong bug in Flash. I'm using CS3 and AS 2.0.

Has anybody encountered this? Any advice or solid workarounds? I'm using depth
levels from 1 upwards, and they're all MovieClips created at runtime. And I'm
not using the timeline or anything...

Thanks
Michael
Re: HELP - serious swapDepths() bug kglad
9/14/2007 11:06:09 PM
Re: HELP - serious swapDepths() bug clbeech
9/15/2007 1:54:55 PM
Kgald's right. If your using getNextHighestDepth(), you must not have to worry
about replacing anything at other depths above your starting point, therefore
why don't you use a simple counter and increament to the next depth. on the
main timeline delcare a variable, then in each 'button' on handler increament
the depth when pressed to bring the window's focus to the top.

var depth:Number = 0;

myWindow.onPress = function() {
depth++;
this.swapDepths(depth);
}
AddThis Social Bookmark Button