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?
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");
}
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")}
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;
}
}
}
}
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.
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
Copy link to clipboard
Copied
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