Your Array was created wrong in your post. Try this:
var days:Array = ["mon", "tues", "wed", "thurs", "fri"];
or you could also create it like this, using the push() method of the Array class:
var days:Array = new Array();
days.push( 'mon');
days.push( 'tues');
days.push( 'weds');
days.push( 'thurs');
days.push( 'fri');
to trace the values of the array in your post:
trace( days[0] ); // returns "mon"
trace( days[1] ); // returns "tues"
trace( days[2] ); // returns "wed"
trace( days[3] ); // returns "thurs"
trace( days[4] ); // returns "fri"
The array's contents are stored in the array's "indexes". An array's index always starts with 0.
Array's have a length. An empty array's length is 0. If the array has at least one item in it, the length is 1 and increases as you add more items. To loop through your array to get the values do this:
for(var i:int = 0; i < days.length; i++)
{
trace( days[i] );
}
Arrays are a powerful and essential part of any programming language. You can remove items from the array, add items, remove a specific item at a specific index, remove an item by name, combine arrays, and lots more. You'd benefit from looking at this link and studying the properties and methods of the Array class. Once you get the hang of how to manipulate Array's you'll never now how you existed without them!
There are many ways to associate a button with a particular array index. The answer provided by Dr.Denis McCracleJizz is one way, although if you are as new to AS3 as you say, it might seem a little overwhelming as it uses several concepts you may not yet be familiar with. Let me see if I can simplify it a bit, although this will make the code a bit more lengthy:
mondayButton.addEventListener( MouseEvent.CLICK, onClickDayButton );
tuesdayButton.addEventListener( MouseEvent.CLICK, onClickDayButton );
function onClickDayButton( e:MouseEvent ):void
{
if( e.target.name == 'mondayButton')
{
trace( days[0] );
}
else if( e.target.name == 'tuesdayButton')
{
trace( days [1] );
}
// and so on...
}
If you're familiar with objects you could create an object for each button that hold both the button and the button id and store those in an array:
var days:Array = ["mon", "tues", "wed", "thurs", "fri"];
var dayButtonArray:Array = new Array();
var mondayButtonObject:Object = new Object();
mondayButtonObject.button = mondayButton;
mondayButtonObject.id = 0;
dayButtonArray.push( mondayButtonObject );
var tuesdayButtonObject:Object = new Object();
tuesdayButtonObject.button = tuesdayButton;
tuesdayButtonObject.id = 1;
dayButtonArray.push( tuesdayButtonObject );
// and like above, the rest of the days here
// then loop through them and set the mouseEvent
for(var i:int = 0; i < dayButtonArray.length; i++)
{
dayButtonArray[i].button.addEventListener( MoouseEvent.CLICK, onClickDayButton );
}
// and the function each button calls to
function onClickDayButton( e:MouseEvent ):void
{
trace( days[ evt.target.id ] );
}
You could further simplify the object method above by skipping the days array altogether and adding the day associated with the button right into the dayButtonArray instead of an id:
var dayButtonArray:Array = new Array();
var mondayButtonObject:Object = new Object();
mondayButtonObject.button = mondayButton;
mondayButtonObject.day = "monday";
dayButtonArray.push( mondayButtonObject );
var tuesdayButtonObject:Object = new Object();
tuesdayButtonObject.button = tuesdayButton;
tuesdayButtonObject.day = "tuesday";
dayButtonArray.push( tuesdayButtonObject );
// and like above, the rest of the days here
// then loop through them and set the mouseEvent
for(var i:int = 0; i < dayButtonArray.length; i++)
{
dayButtonArray[i].button.addEventListener( MoouseEvent.CLICK, onClickDayButton );
}
// and the function each button calls to
function onClickDayButton( e:MouseEvent ):void
{
trace( evt.target.day );
}
Now were getting as complicated as Dr.Denis McCracleJizz's answer. His is definitely worth looking at as well.