• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Possible:Booleans in Arrays?

Community Beginner ,
Jul 18, 2012 Jul 18, 2012

Copy link to clipboard

Copied

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?

TOPICS
ActionScript

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 18, 2012 Jul 18, 2012

Copy link to clipboard

Copied

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");

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 18, 2012 Jul 18, 2012

Copy link to clipboard

Copied

Let's say I have this array:

var buttons:Array=[button1, button2,button3]

Instead of doing this for each index:

var button1:Boolean=false

I would like to do something like this:

buttons:Boolean=false

Then I would like to be able to do something like this for conditional:

if (buttons=true){trace ("true")}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 18, 2012 Jul 18, 2012

Copy link to clipboard

Copied

then you can just use buttons = false;

and

if (buttons == 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)

                                        {

                                                  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 = false;

                              }

                    }

          }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 18, 2012 Jul 18, 2012

Copy link to clipboard

Copied

Ok, I've been playing around with this and it looks like you have to define the contents of the array as a variable first, then define the contents as a variable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 19, 2012 Jul 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 19, 2012 Jul 19, 2012

Copy link to clipboard

Copied

LATEST

Thanks. This is the code:

var button1, button2,button3;

var buttons:Array=[button1, button2,button3];

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

buttons=false;

for (var j:uint=0;j<buttons.length; j++)

if (buttons!=true){trace()}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines