swapDepths() strangeness
hello,
i’ve been trying swap depths working long time , seems giving me random results.
my problem have bunch of clips on stage added randomly @ random y-positions. higher y positions must higher depth ones @ lower y position. basically, bottom clips, overlap clips above it.
the first way tried every time new clip added (they aren’t added @ once, via user interaction) store chips array , sort them y-position, lowest value y (the highest clip on stage) appear first. go through whole array again , call “clip.swapdepths(parentclip.getnexthighestdepth())”.
my reasoning first clip set nexthighestdepth overlapping clips. next clip in array set nexthighestdepth, overlapping previous clip before, , forth until last clip in array set nexthighestdepth, overlapping of clips.
the result of ended odd looking like:
index 0 – depth 4
index 1 – depth 1
index 2 – depth 0
index 3 – depth 2
index 4 – depth 5
notice skips depth ‘3’.
i discovered can set depths directly passing in number , if clip existed in depth value, swapped instead of replaced. tried going (after sorting): clip.swapdepths(counter); -where counter array index in:
for(var counter:number = 0; counter < array.length; counter++){
array[counter].swapdepths(counter);
}
but resulted in same result first method.
just fun, decided go (in above loop) “array[counter].swapdepths(counter * 2);”
but when traced out depth, got depths 3,5,9,11 –not numbers.
this leads me conclude there not right expectation of swapdepths().
any ideas on what's going on swapdepths() or better way solve problem?
i’ve been trying swap depths working long time , seems giving me random results.
my problem have bunch of clips on stage added randomly @ random y-positions. higher y positions must higher depth ones @ lower y position. basically, bottom clips, overlap clips above it.
the first way tried every time new clip added (they aren’t added @ once, via user interaction) store chips array , sort them y-position, lowest value y (the highest clip on stage) appear first. go through whole array again , call “clip.swapdepths(parentclip.getnexthighestdepth())”.
my reasoning first clip set nexthighestdepth overlapping clips. next clip in array set nexthighestdepth, overlapping previous clip before, , forth until last clip in array set nexthighestdepth, overlapping of clips.
the result of ended odd looking like:
index 0 – depth 4
index 1 – depth 1
index 2 – depth 0
index 3 – depth 2
index 4 – depth 5
notice skips depth ‘3’.
i discovered can set depths directly passing in number , if clip existed in depth value, swapped instead of replaced. tried going (after sorting): clip.swapdepths(counter); -where counter array index in:
for(var counter:number = 0; counter < array.length; counter++){
array[counter].swapdepths(counter);
}
but resulted in same result first method.
just fun, decided go (in above loop) “array[counter].swapdepths(counter * 2);”
but when traced out depth, got depths 3,5,9,11 –not numbers.
this leads me conclude there not right expectation of swapdepths().
any ideas on what's going on swapdepths() or better way solve problem?
store movieclips in array (which you've done), use custom sort function sort array movieclip's _y property , store depths of movieclips in array sort in ascending (or descending) order. finally, iterate through sorted movieclip array swapping each movieclip's depth corresponding depth in array of sorted depths.
More discussions in ActionScript 1 and 2
adobe
Comments
Post a Comment