A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] sorting movieclips according to y values

Threaded View

  1. #1
    Join Date
    Nov 2009

    resolved [RESOLVED] sorting movieclips according to y values

    In the project I'm working on, there are towers the user can place. However, it you place a tower higher then another one, it appears infront of that one, which looks weird.

    I want to be able to arrange all the towers so that that does not happen.

    There is an sprite called towerHolder holding, which all the towers are children of, and an array called towerArray, which the towers get pushed to when they are created.

    I tried clearing towerHolder, then running the sortOn() function on the array, and then adding each tower back to the towerHolder, but the towers just seem to be randomly placing themselves irrelevent to their height.

    Here's my code for the relevant parts:

    Actionscript Code:
    function clearTowers():void {
        while (towerHolder.numChildren > 0) {

    function orderTowers():void {
        towerArray = towerArray.sortOn(y, Array.NUMERIC);
        for each (var tower in towerArray) {
    So yeah if you could help me so that I have a function I can called to order the towers correctly, that would be great.
    Last edited by Jezzamon; 11-06-2010 at 11:45 PM. Reason: tyops

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center