A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Stepping through an Array with next and back buttons

  1. #1
    Senior Member
    Join Date
    Jul 2000
    Posts
    131

    Stepping through an Array with next and back buttons

    I'm working on a presentation type page that has a lot of animation in it. I've tried various ways to make the next slide and previous slide work but they've all had drawbacks.

    I've finally ended on making a mc with each slide on a different frame with labels. I then loop through those labels to create an array. This I've done and it works beautifully. However, I'm new to AS and don't know how to make my next and back buttons step through each of the elements in the array.

    What I need it to do is to press the next button and perform a function, which will hold a lot of AS animation in it.

    I know the easiest way to help people is to have their fla, so here it is.
    linked fla file

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    You can either use a marker variable that you increment or decrement:

    PHP Code:
    currentPosition++;
    currentPosition %= array.length;
    //  do stuff to array[currentPosition] 

    Or you can shift the entire array so that the first position is always your desired target...I prefer this method since you don't have to keep an extra variable around and you don't have to check for array length:

    PHP Code:
    //  last element becomes [0]
    array.unshift(array.pop());
     
    //  [0] becomes last element
    array.push(array.shift());

    //  do stuff to array[0] 

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