Skip to main content
Inspiring
April 14, 2011
Answered

for statement for gotoAndStop plz help!

  • April 14, 2011
  • 3 replies
  • 511 views

Hi,

NumberDots();

var myvar

function NumberDots():void

{

for (var i:int=1; i<=5; i++)

{

myvar = "btn"

trace(i)

myvar+i.gotoAndStop(i)

trace("looped " + i);

trace("myvar = " + myvar);

}

}

I have this code and am trying to get the 5 btns on my screen to go to a diffrent keyFrame each

first one to frame1 second to 2 and etc

if u can help ill rly apriciate it

thx pavel

This topic has been closed for replies.
Correct answer

var buttons:Array = new Array(btn1, btn2, btn3, btn4, btn5);


NumberDots();


function NumberDots():void {

    for (var i:int=0; i < buttons.length; i++) {
   
    var frame:Number = i+1;
    buttons.gotoAndplay(frame);
   
    }
}

Put the buttons in an array and refer to array instead. In the array simply put the instance names of the buttons. in the order you want them to move (1,2,3).

3 replies

pa-pavelAuthor
Inspiring
April 15, 2011

Thx guys this rly helped!

Kenneth Kawamoto
Community Expert
Community Expert
April 14, 2011

this[myvar + i].gotoAndStop(i);

Correct answer
April 14, 2011

var buttons:Array = new Array(btn1, btn2, btn3, btn4, btn5);


NumberDots();


function NumberDots():void {

    for (var i:int=0; i < buttons.length; i++) {
   
    var frame:Number = i+1;
    buttons.gotoAndplay(frame);
   
    }
}

Put the buttons in an array and refer to array instead. In the array simply put the instance names of the buttons. in the order you want them to move (1,2,3).