Skip navigation
Currently Being Moderated

Possible:Booleans in Arrays?

Jul 18, 2012 2:27 AM

I would like to use an array to A)define the Boolean state of a group of variables and B) check those variables. I have tried a bunch of different methods of doing this but get a bunch of different errors. Is this actually something that's possible? What would sample code look like?

 
Replies
  • Currently Being Moderated
    Jul 18, 2012 3:02 AM   in reply to witherton

    definately possible, several different ways of doing no different to anything else really

     

    post code and errors for specific help

     

    var i:int = -1

     

     

    var boolArray:Array = [true, false, 3>2, true, false, false, i == -2, true];

    trace("4th bool: " + boolArray[3])

     

     

    if (boolArray[2])

    {

              trace("3rd bool is true");

    }

    else

    {

              trace("3rd bool is false");

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 18, 2012 4:06 AM   in reply to witherton

    then you can just use buttons[i] = false;

     

    and

     

    if (buttons[i] == true) {trace("true")}

     

    (note using single = is an assigment not an equality)

     

    here is another demo that might help

     

    package

    {

              import flash.display.Sprite;

     

              public class Main extends Sprite

              {

                        private var buttons:Array;

     

                        public function Main()

                        {

                                  buttons = new Array();

     

                                  setUpButtons(6);

     

                                  testButtons();

                        }

     

                        private function testButtons():void

                        {

                                  for (var i:int = 0; i < buttons.length; i++)

                                  {

                                            if (buttons[i])

                                            {

                                                      trace("button " + i + " is true");

                                            }

                                            else

                                            {

                                                      trace("button " + i + " is false");

                                            }

                                  }

                        }

     

                        private function setUpButtons(len:int):void

                        {

                                  for (var i:int = 0; i < len; i++)

                                  {

                                            buttons[i] = false;

                                  }

                        }

              }

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 19, 2012 12:52 AM   in reply to witherton

    that will work but is not the case if you want to paste your code here I can get it to work without the variables first

     
    |
    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