dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Swap Depths Confusion

  1. #1
    Getting There! bitsk308's Avatar
    Join Date
    Jul 2000
    Location
    Phoenix, AZ
    Posts
    427

    Swap Depths Confusion

    Howdy Gang,

    I was trying to help another user with a swapDepths problem. Picture a bird's eye view of a stack of photos, with a corner at least of each one hanging out. Clicking an associated button would move that mc to the top of the stack. Then the next one you clicked would go to the top too, and the one you selected first would now be second. I set up an array to hold all the clips and used splice and push to rearrange the array each time and maintain the stacking order. Then i figured i'd just go through the array with something like this:
    code:

    for(n=0;n<my_array.length;i++){
    my_array[n].swapDepths(n);
    }



    Seems like this would stack them visually the same way they're stacked in the array. But for some reason I can't peg for the life of me, the last element in the array always traces undefined when i try getDepth(). and the whole thing falls apart from there. It works fine up until the last one, then...nothing.

    Any ideas?

  2. #2
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    Code:
    for(n=0;n<my_array.length;n++){
    
      my_array[n].swapDepths(n);
    
    }
    New sig soon

  3. #3
    Getting There! bitsk308's Avatar
    Join Date
    Jul 2000
    Location
    Phoenix, AZ
    Posts
    427

    Splice vs. Push

    Thanks for the reply. That was a typo in the post, not the code. But as it turns out... the swapDepths() wasn't my problem, it was the splice and push that were doing me in.
    code:

    // This won't work
    var shift = order_array.splice(n,1);
    order_array.push(shift);

    // This will
    var shift = order_array.splice(n,1);
    order_array.push(shift[0]);



    Once my array was populated correctly, the method to swapDepths I was using worked fine. Take care

    _b

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