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?
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");
}
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[i]:Boolean=false
Then I would like to be able to do something like this for conditional:
if (buttons[i]=true){trace ("true")}
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;
}
}
}
}
North America
Europe, Middle East and Africa
Asia Pacific