Skip navigation
Currently Being Moderated

Turning if statement into variable?

Jun 22, 2012 9:20 AM

I have a group of movie clips on the stage that belong to an array called "bttns". All consist of the same  3 frame labels: "no_color", "red"and "blue" . When the program starts, each of the buttons is either on frame "no_color" or "red". Their currentframes are determined by a randomizer code that fires off at start. I want a second randomizer to select one button  from an array of "red" buttons to turn "blue". I've tried a few different things with for loops and while loops, but none does exactly what I want in an elegant way.

 

When I trace the the following function, I get exactly the array I want.

 

{

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

if (bttns[i].currentLabel != "blue"){trace(bttns[i].name)}

}

 

However, I don't know how to turn this code into a variable. If I use the "!=" tag in a variable definition, it traces as true or false.Is it possible to do so?

 
Replies
  • Currently Being Moderated
    Jun 22, 2012 9:56 AM   in reply to witherton

    {

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

         if (bttns[i].currentLabel == "red" && Math.random()>0.5){

              bttns[i].gotoAndStop("blue"))

        }

    }

     

    With this, take all the red buttons and have 50% to turn into blue

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 22, 2012 11:11 AM   in reply to witherton

    var onlyRed:Array;

    var i:uint;

     

    onlyRed=new Array();   //Clear the array before init the for

    for(i=0; i<bttns.length; i++)

         if (bttns[i].currentLabel == "red"){  // or if (bttns[i].currentLabel != "blue"){

             onlyRed.push(bttns[i]);

        }

    }

    i=int(Math.random()*(onlyRed.length-1));

    bttns[i].gotoAndStop("blue"));

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 22, 2012 1:17 PM   in reply to witherton

    you're welcome

     
    |
    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