Skip navigation
Currently Being Moderated

For Loop Problems?

May 24, 2012 2:28 AM

For Loop Problems?

 

I want to write a simple conditional statement

in which a button moves to a certain group of frames when clicked depending on its current frame. This is the code I'm using.

 

var group1:Array=["b1","b2","b3"];

var group2:Array=["b12","b22","b32"]

 

mainbutton.addEventListener(MouseEvent.CLICK, buttonflash)

function buttonFlash (e:MouseEvent)

{

     for (var i:uint=0; i<group1.length; group1++)

    {if

       (e.target.currentLabel == group1[i])

       {e.target.gotoAndStop(e.target.currentLabel +     "2")}

  

    else

       {e.target.gotoAndStop(e.target.currentLabel.slice(0,2))}  

 

 

  }

}

 

 

However, when I include the for loop in the function, it causes the function to run the number

of times of the variable. In testing, I switched out the else statement with a trace string and the string showed up in the output window three times.

When I place the for loop outside of the function, the output compiler says the variable is undefined. Any ideas as to what I'm doing wrong?

 
Replies
  • Currently Being Moderated
    May 24, 2012 3:00 AM   in reply to witherton

    it should be i++ not group1++

     
    |
    Mark as:
  • Currently Being Moderated
    May 24, 2012 5:24 AM   in reply to witherton

    for (var i:uint=0; i<group1.length; group1++)

     

    start with i = 0 then while i is less than the length of the array group1 do something andthen add 1 to group1

     

    this makes no sense

     

    you need i++ so increases and the i<group1.length will eventually equate to false

     

    changin group1++ to i++ may not solve the problem but it's definately a correct change

     

    I am suprised group1++ even compiles

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points