Hi
I wanted to try and build an event calendar. I have the calendar portion working fine except i cannot wrap my head around the right way to both determine the first day of the month for any given month and subsequently shifting the first day movie clip to the correct position under the correct day title.
here is the actionscript i have so far;
ActionScript Code:
stop ();
Stage.showMenu = false;
// setup needed date variables
currentDate = new Date();
currentYear = currentDate.getFullYear();
currentMonth = currentDate.getMonth();
currentDay = currentDate.getDate();
currentDayNum = currentDate.getDay();
// define some arrays to handle date information
monthName = new Array();
numDays = new Array();
dayName = new Array();
// handle February on a Leap Year
if (currentMonth == 1){
if ((currentYear%4) == 0){
numDays[1] = 29;
} else {
numDays[1] = 28
}
};
// define how many days in each month
numDays[0] = 31;
// February handled by above if statement
numDays[2] = 31;
numDays[3] = 30;
numDays[4] = 31;
numDays[5] = 30;
numDays[6] = 31;
numDays[7] = 31;
numDays[8] = 30;
numDays[9] = 31;
numDays[10] = 30;
numDays[11] = 31;
// define names of the month
monthName[0] = "JANUARY";
monthName[1] = "FEBRUARY";
monthName[2] = "MARCH";
monthName[3] = "APRIL";
monthName[4] = "MAY";
monthName[5] = "JUNE";
monthName[6] = "JULY";
monthName[7] = "AUGUST";
monthName[8] = "SEPTEMBER";
monthName[9] = "OCTOBER";
monthName[10]= "NOVEMBER";
monthName[11]= "DEVEMBER";
// define the names of each day
dayName[0] = "SUN";
dayName[1] = "MON";
dayName[2] = "TUE";
dayName[3] = "WED";
dayName[4] = "THU";
dayName[5] = "FRI";
dayName[6] = "SAT";
// set some positioning parameters
yStartPos = 0;
xStartPos = 515;
xSpacing = 51.5;
ySpacing = 83;
cCount = 0; // counts number of columns
rCount = 0; // counts number of rows
dCount = 0; // counts number of days
//build the months worth of days
this.onEnterFrame = function() {
if (dCount < numDays[currentMonth]) {
var dayClip = dayHolder.attachMovie ("dayBox", "dayBox" + dCount, dCount);
dayTween = new mx.transitions.Tween(dayClip, "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 2.5, true);
dayTweenX = new mx.transitions.Tween(dayClip, "_width", mx.transitions.easing.Regular.easeOut, 0, 100.2, 1, true);
dayTweenY = new mx.transitions.Tween(dayClip, "_height", mx.transitions.easing.Regular.easeOut, 0, 81, 1, true);
dayClip.dayText.text = dCount+1;
if (cCount > 1 && (cCount%7)==0){
cCount = 0;
rCount++;
}
if (dCount == 0) {
dayClip._x = xStartPos;
cCount = 6; // needs to eventually be changed with first day of the month variable
dCount++;
} else {
dayClip._x = cCount++ * xSpacing;
dayClip._y = rCount * ySpacing;
cCount++;
dCount++;
}
} else {
delete this.onEnterFrame;
}
};
I hard set the _x starting position that works for the month of June but i would need to replace that with another variable once i figure out how to automatically determine the 1st day of any month and use a corresponding array to set the _x positions for any of the 7 possible starting days.
does anyone have some suggestions?