actionscript 3 - as3 ARRAY SHIFT - the End of array now what? -
i having alphabet go on , off screen. using array shift go next letter. when last element of array, letter z, how can go beginning?
another example if had array of pictures , after done viewing last 1 code take begining again , start viewing there.
here code need set shift zero.
var letter:movieclip; function fl_mouseclickhandler_2(event:mouseevent):void { if(letter) { var gone:movieclip = letter 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); /// key code line 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 not work alphabet.unshift(27); } /// code use here set array beginning? if(alphabet.length==0) { alphabet.shift = 0; /// ??? }
shift()
removes element array cannot unless keep somewhere else put in array when need again.
you had better use index variable find right element in array without modifying it: if index value larger 26, start @ 0 again.
or, use push()
put letter @ end of array after shifting. way array never gets empty.
Comments
Post a Comment