hi, need some help here.
i have created a calendar using actionscripts. one of the problems i have yet to solve is how to scroll to previous/next months. i have created an input table whose text will change accordingly when i use some buttons, but i cannot get the dates of the calendar to update at all. i would really appreciate any help/advice.
thank you.
currentDate = new Date(); //current date
month = currentDate.getMonth(); //current month (month janurary = 0)
todayDate = currentDate.getDate(); //todays date
day = currentDate.getDay(); //current day of week (sunday = 0)
year = currentDate.getFullYear(); //current year
lastdate=new Date(year, month+1, 0);//get the number of days in the current month
lastday=lastdate.getDate(); // get the lastdate
lastMonthDate=new Date(year, month, 0);//get the number of days in the last month
lastMonthDay=lastMonthDate.getDate(); // get the lastdate
var firstDay = new Date(this.year, this.month, 1);
var startingDay = firstDay.getDay(); // returns first weekday of month
var lastMonth = lastMonthDay - startingDay + 1;
Date.daysOfWeek = new Array("Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday");
DATE.months = new Array("January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");
_root.createEmptyMovieClip("calendar", 0);
this.createEmptyMovieClip("weekName", 0)
var distance = 0;
for (var i = 0; i < Date.daysOfWeek.length; i++)
{
this.weekName.createTextField("weekDay" + i, i, distance, 110, 135, 30);
var wD = this.weekName["weekDay" + i];
wD.text = Date.daysOfWeek*;
distance = distance + 135;
wD.border=true;
wD.background=true;
wD.backgroundColor=0xE0DFE4;
wD.borderColor=0x000000;
wD.textColor = 0x000000;
titleStyle = new Textformat();
titleStyle.size=22;
titleStyle.font="century";
titleStyle.align="center"
wD.setTextFormat(titleStyle);
}
/////changing months/////////////////////////////
//advance month
inputDate.text = Date.months[month] + " " + year; //input text instance name
plusMonth.onRelease = function()
{
month = month + 1;
if (month > 11)
{
month = 0;
year = year + 1;
}
var newMonth = month;
inputDate.text = Date.months[newMonth] + " " + year;
lastdateNew=new Date(year, newMonth, 0);//get the number of days in the current month
lastdayNew=lastdateNew.getDate(); // get the lastdate
lastMonthDateNew = new Date(year, newMonth + 1, 0);//get the number of days in the last month
lastMonthDayNew = lastMonthDateNew.getDate(); // get the lastdate
CalendarDateNew = new Date();
CalendarDateNew.setMonth(newMonth);
firstDayNew = new Date(year, newMonth, 1);
startingDayNew = firstDay.getDay(); // returns first weekday of month
lastMonthNew = lastMonthDayNew - startingDayNew + 1;
}
//retreat month
minusMonth.onRelease = function()
{
month = month - 1;
if (month < 0)
{
month = 11;
year = year - 1;
}
inputDate.text = Date.months[month] + " " + year; //input text instance name
trace(inputDate.txt);
lastdate=new Date(year, month, 0);//get the number of days in the current month
lastday=lastdate.getDate(); // get the lastdate
lastMonthDate = new Date(year, month + 1, 0);//get the number of days in the last month
lastMonthDay = lastMonthDate.getDate(); // get the lastdate
CalendarDate = new Date();
CalendarDate.setMonth(month);
firstDay = new Date(year, month, 1);
startingDay = firstDay.getDay(); // returns first weekday of month
lastMonth = lastMonthDay - startingDay + 1;}
//Number of Days in Month
var distance = 0;
var height = 120;
var count = 0;
var y = 140;
var width = 135;
var repeat = 0;
var plus = 0;
var final = 0;
var dN;
this.createEmptyMovieClip("dateNumber", 2)
for (var j = 0; j < Date.daysOfWeek.length; j++)
{
this.dateNumber.createTextField("dateNum" + count, count, distance, y, width, height);//if i change count to 0, only the #7 will appear in the last column on the right; if i change distance to 0, only the #7 will appear, but in the first column on the left
var lastMonth = lastMonthDay - startingDay + 1;
if (j < startingDay && repeat == 0)
{
lastMonth = lastMonth + j;
dN.text = lastMonth;
dN.border = true;
dN.background = true;
dN.backgroundColor = 0xB2D497;
dN.borderColor=0x000000;
dN.textColor = 0x000000;
titleStyle = new Textformat();
titleStyle.size = 18;
titleStyle.font = "century";
titleStyle.align = "left";
dN.setTextFormat(titleStyle);
distance = distance + 135;
final++;
}
else if(repeat=!0)
{
dateNum = startingDay;
dN = this.dateNumber["dateNum" + count];
distance = distance + 135;
dN.text = count + 1;
dN.border = true;
dN.background = true;
dN.backgroundColor = 0xD6ECBD;
dN.borderColor = 0x000000;
dN.textColor = 0x000000;
titleStyle = new Textformat();
titleStyle.size = 18;
titleStyle.font = "century";
titleStyle.align = "left";
dN.setTextFormat(titleStyle);
count++;
final++;
}
if (j==6)
{
y = y + height;
j = -1;
distance = 0;
repeat++;
}
if(currentDate.getDate()==count)
{ // if the current day is today, change it's color
dN.textColor = 0x74B560;
}
if (count > lastDay)
{
dN.text = plus + 1;
plus++;
dN.border = true;
dN.background = true;
dN.backgroundColor = 0xB2D497;
dN.borderColor = 0x000000;
dN.textColor = 0x000000;
titleStyle = new Textformat();
titleStyle.size = 18;
titleStyle.font = "century";
titleStyle.align = "left";
dN.setTextFormat(titleStyle);
}
if(final == 42)
{j = 6;}
}