as3 ARRAY SHIFT - the End of array now what?

I am having the alphabet go on and off screen. I am using the array SHIFT to do this to go to the next letter. When I get to the last element of the array, the letter Z, how can I go to the beginning?

Another example would be if you had an array of pictures and after you are done viewing the last one the code would take you to the begining again and you start viewing from there.

Here is the code where I need to set the shift back to zero.

var Letter:MovieClip;
function fl_MouseClickHandler_2(event:MouseEvent):void
{
    if(Letter) 
    {
        var gone:MovieClip = Letter as MovieClip;
        TweenMax.to(Letter, 1, { x:0 ,  ease:Back.easeOut, onComplete:removeLetter});
        function removeLetter(){

            removeChild(gone);
        }

    }
    if(Alphabet.length!=0)
    { 

        Letter = new alphabetLetter();
        addChild(Letter);
        /// THIS KEY CODE LINE THAT USES SHIFT

        Letter.letter.text = Alphabet.shift();  

        TweenMax.fromTo(Letter, 2, {x:stage.stageWidth}, {x:stage.stageWidth/2-Letter.width, ease:Expo.easeOut});
    }
    else
    {
           //// TRIED THIS BUT DOES NOT WORK            
          Alphabet.unshift(27);
    }

    /// WHAT CODE DO I USE HERE TO SET THE ARRAY BACK TO THE BEGINNING?



    if(Alphabet.length==0)
    { 
           Alphabet.shift = 0; /// ???
    }

Answers


shift() removes an element from an array so you cannot get it back unless you keep it somewhere else to put it back in the array when you need it again.

You had better just use an index variable to find the right element in the array without actually modifying it: then if your index value is larger than 26, start at 0 again.

Or, use push() to put the letter back at the end of the array immediately after shifting. That way your array never gets empty.


Need Your Help

Will HTML5 video source URL follow header redirects?

video html5 redirect http-headers

Right now I am still using flash as primary player and have a HTML5 fallback, because its still buggy especially when it comes to codes.

Mysql: enum confusion

sql mysql database-design data-modeling enums

I have an employee table, employee has interests, so the table can be designed like this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.