A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [AS3] Swapping/Arraging Depths?

  1. #1
    Junior Member
    Join Date
    May 2007
    Posts
    3

    Question [AS3] Swapping/Arraging Depths?

    Hey there FK forums! It's late, so I'm just going to jump right to the point.
    I'm an AS3 noob and I'm making a game - Game Link, click to place blocks - and I'm having issues with it (Surprisingly!).

    Basically, I'm trying to get the depths of all the blocks to be at the correct levels at the correct times so that the 3d effect is maintained.
    I've tried many things, but have had little success.

    All the instances of the blocks are stored in an array, but since it's adding them in accordance with when they're added to the stage, it doesn't help me locate them to swap depths. Is there a way to arrange them by location on the board?

    Does anyone have any suggestions about how get the depths right?
    Thank you in advance.
    Last edited by icepyro_aj; 12-30-2009 at 06:48 PM.

  2. #2
    Member
    Join Date
    Apr 2006
    Posts
    37
    I've used the sortOn method of the Array class to do something like this before. Basically, you dump everything into an array, then sort all your items by their x or y coordinates. After its in the correct order, you can loop through whatever container you're placing your blocks in and use setChildIndex to the order in the array.

    It looks like it's not going to be that simple though, because whatever is closest to the middle should be at the top depth. If I remembered how to do this properly I'd probably be more helpful. But definitely check out sortOn and setChildIndex if you haven't already tried it.
    Last edited by Sub Tank; 12-30-2009 at 10:53 AM.

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