# Dynamic Z Depth Sorting

**URL:** <https://forum.kirupa.com/t/dynamic-z-depth-sorting/228666>\
**Category:** flash\
**Created:** [June 10, 2007, 10:22am UTC](https://forum.kirupa.com/t/dynamic-z-depth-sorting/228666 "2007-06-10T10:22:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charleh](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Charleh](https://forum.kirupa.com/u/Charleh)\
**Post date:** [June 10, 2007, 10:22am UTC](https://forum.kirupa.com/t/dynamic-z-depth-sorting/228666/1 "2007-06-10T10:22:45Z")

</div>

Does anyone know a quick way of sorting objects depths based on a variable (z depth). I’ve tried a few things but they seem quite slow -

one method involved pushing each object onto an array and then sorting it each frame using a sort function and then using swapDepths to reorder everything on screen. The swapDepths is quick but I think the array sorting is slow. I could possibly write a quicker sort based on shear or merge sorting - are the default actionscript sorts slow?

Does anyone know if it’s any quicker in AS3.0 either?

I could probably work it out given a while, but I thought I’d ask if anyones already done it! 😛

Cheers!
