views:

53

answers:

1

i have a few movieclips on the stage, all the movieclipsnames are in an array togheter with what should be the depth. i need a way to set the depths according the numbers in the array.

sample a$ = [{name:"item_name_1", depth: 10},{name:"item_name_2", depth: 11},{name:"item_name_3", depth: 12},{name:"item_name_4", depth: 13},{name:"item_name_5", depth: 14}]

i need something like: set_depth(target_name, depth)

i know i can swap the depths with an other movieclip, but that results in wrong depth for some clips

thanks

+1  A: 
   myArray.sortOn("depth", Array.NUMERIC);


    //assuming depth number means it is higher otherwise iterate in reverse
    for (var i:int = 0; i < myArray.length;i++)
    {
      addChild(myArray[i]);
    }
Allan
but the objects are allready on the stage
mel
that doesn't matter. When you call addChild() it removes it if it exists and places back on top as the next item. This piece of code works, I have used it before ;-)
Allan
wow it does thanks
mel