PDA

View Full Version : Can someone look at this calendar code, changing month is messed up.


Hofmann
09-29-2004, 07:08 PM
Hey, im making a calendar component for å page and it works pretty well except for when I change the month. It then mess up everything and I really dont know wich month its suppose to display. Im using some date functions from the library at this site and they work pretty good when I just feed them with a exact date, but now I want to change the month with som buttons. This is the code for month change:


this.dateObj = new Date()
this.currentMonth = this.dateObj.getMonth()
this.currentYear = this.dateObj.getFullYear()



this._parent.currentMonth -= 1
this._parent.dateObj.setDate(this._parent.currentY ear,this._parent.currentMonth-1)
this._parent.dateStart = this._parent.dateObj.getMonthStartDay()
this._parent.dateEnd = this._parent.dateObj.getDaysInMonth()

trace(this._parent.dateObj.getDate())





Date.prototype.getDaysInMonth = function() {
var temp = this
for (var i=28; i<=(this.dateObj.getMonth()!=1? 31:29); i++)
{
temp.setDate(i);
if (i==temp.getDate()) { var days=i; }
}
return days;
}

// <num> = Starting day of the week (0-6)
Date.prototype.getMonthStartDay = function()
{
var tdate = this
return tdate.getDay();
}




The trace returns 31 as the date of nearly every month, except for sometimes its the first in the month, wtf???

currentMonth is a variable I made at Init wich is just an Int. Is there another way for me to change the date without setting the date like I do?
Sorry bout the noob questions, but I thought this would be pretty straight forward...

Let me know if u need any more code.

farafiro
09-30-2004, 07:46 AM
I don'tknow exactly what is wont but "myDate.setDate()" only get one parameter
in your code u put two
this._parent.dateObj.setDate(this._parent.currentY ear,this._parent.currentMonth-1)

Hofmann
09-30-2004, 07:54 AM
oh, hehe, I thought it set a complete date like new Date, but ill try with just the date param, it makes sence actually since there is setYear and such ;)

Hofmann
09-30-2004, 08:36 AM
:( I didnt help, the thing that bothers me is that the internal loading system for my calendar is reporting that its at the correct month, but the rest of the system is just plain wrong... Does anyone have a little calendar they have made that I could take a look at that changes month in a easy manner? It would help alot since my dealine is today in 5hours ;) Damn!

farafiro
09-30-2004, 08:47 AM
see the calender components that comes with Flash

Hofmann
09-30-2004, 10:34 AM
Might be a stupic question, but how do I "see" those components, they are locked, cant edit any of them??

farafiro
09-30-2004, 10:44 AM
look in:
Program files>> Macromedia MX 2004>> Flash MX2004>> en>> First Run>> Classess>> MX>> Controls>> calenderlayour.as

Hofmann
09-30-2004, 01:30 PM
ahh, k, thanks alot :)

farafiro
10-03-2004, 07:10 AM
Welcome
;)