You can make it a lot easier by doing some of the prep work for that
architecture in the for loop that you use to first create and assign
depths to those movieclips.

This isn't exactly OOP, but it demonstrates the architecture:

var qtyClips:Number = 4;
var nbrDepthOffset:Number = 7;
var rraClips:Array = new Array();
var nbrLastPressed:Number;
//
function fncClipInit() {
        for (var i = 0; i<qtyClips; i++) {
                var nbrDepth:Number = i+nbrDepthOffset;
                var rfcClip:MovieClip = createEmptyMovieClip("item"+i, 
nbrDepth);
                rfcClip.nbrIDX = i;
                rfcClip.nbrDepth = nbrDepth;
                rraClips[i] = rfcClip;
                //
                // -------------------------------------------------------
                // This part just so there's something to see...
                var rraDim:Array = [[Math.random()*600, Math.random()*300],
[Math.random()*600, Math.random()*300]];
                rfcClip.beginFill(Math.floor(Math.random()*0xFFFFFF), 100);
                rfcClip.lineStyle(2, Math.floor(Math.random()*0xFFFFFF), 100);
                rfcClip.moveTo(rraDim[0][0], rraDim[0][1]);
                rfcClip.lineTo(rraDim[1][0], rraDim[0][1]);
                rfcClip.lineTo(rraDim[1][0], rraDim[1][1]);
                rfcClip.lineTo(rraDim[0][0], rraDim[1][1]);
                rfcClip.lineTo(rraDim[0][0], rraDim[0][1]);
                rfcClip.endFill();
                // -------------------------------------------------------
                //
                rfcClip.onPress = function() {
                        fncDepthSort(this);
                };
        }
}
//
function fncDepthSort(rfcBtn:MovieClip) {
        if (rfcBtn.nbrIDX != nbrLastPressed) {
                var rfcClip:MovieClip = rraClips[rfcBtn.nbrIDX];
                rraClips.splice(rfcBtn.nbrIDX, 1);
                rfcClip.swapDepths(qtyClips+nbrDepthOffset);
                rraClips.push(rfcClip);
                for (var i = 0; i<rraClips.length; i++) {
                        rraClips[i].swapDepths(i+nbrDepthOffset);
                        rraClips[i].nbrIDX = i;
                }
                nbrLastPressed = rfcBtn.nbrIDX;
        }
        trace("rraClips: "+rraClips);
}
//
fncClipInit();
trace("rraClips: "+rraClips);



-- 
Byron "Barn" Canfield


> Does anyone have a an algorithm for Z sorting multiple overlapping
> clips...
>
> I have an array of clips and when one is clicked I want it to come to
> the top, but I want the other overlapping items to also shift
> appropriately...
>
> So
>
> Item [1] at depth 10
> Item [2] at depth 9
> Item [3] at depth 8
> Item [4] at depth 7
>
> If you click item [4], it would go to depth 10, and the other would
> shift down 1
>
> Item [4] depth 10
> Item [1] depth 9
> Item [2] depth 8
> Item [3] depth 7
>
> But if any of those items are overlaping other items, they also need to
> be Z sorted.
>
> I'd rather not re-invent the wheel.
>
> Thanks
> Grant
> _______________________________________________
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to