Advanced Features
There are 2 types of events that you can handle with this component:
plain events - events that can occur once or multiple times without having any particular order
recurrent events - events that reoccur at regular intervals. For example, a birthday is an event that occurs on the same date each year.
To define a date as a holiday you will use the addEvent method or you can do this using an XML file. Here is the code for adding an event using ActionScript:
var obj={};
obj.date=new Date(2004,4,5);
obj.state="holiday";
obj.content="This is 5th of may, 2004";
calendar_mc.addEvent(obj);
It is usually easier to define events using an XML file. Please read the Using XML part of the userguide for more information.
To 'capture' the events of the user interaction with the calendar, you will need to use the event methods of this component. Let's say that we have a calendar component on the stage, named myCalendar, with some predefined calendar events. When the user clicks on a certain date button, the component will trigger the onDateClick event method and pass to it some parameters. To 'capture' them you need to define the following function in the same frame of the timeline containing the component:
myCalendar.onDateClick=function(mc,eobj,robj)
{
// some code
}
There are 3 parameters passed to this function:
mc - points to the date movie clip button that has been clicked. In most of the cases you will want the date property in order to retrieve the date of the button that has been clicked.
eobj - object with event (non-recurring) properties for a certain date.
Event object properties are:
| property | description |
| state | the state of the date movie clip button that has been clicked |
| value | the value of the date movie clip button that has been clicked |
| content | content text associated with date |
robj - array of objects with recurrent properties for a certain date.
Recurrent event object properties are:
| property | description |
| state | the state of the date movie clip button that has been clicked |
| value | the value of the date movie clip button that has been clicked |
| content | content text associated with date |
| type | shows if the event is repeated periodically every year, month, week or day. |
| pattern | the repeating pattern For example: "1" means that the event is repeated each period type. If current year is 2004 and the type is "year", "0,1" means that the event is happening in 2005, 2007, 2009 etc. |
Depending on recurrent event type other possible properties are
| property | description |
| month | Defines the month in which the event is happening |
| yearweek | Defines the week of the year in which the event is happening |
| week | Defines the week of the month in which the event is happening . Negative values are also possible. For example -1 will be last week of the month (when the type is month). |
| yearday | Defines the day of the year in which event is happening |
| monthday | Defines the day of the month in which the event is happening |
| day | Defines the day of the week in which the event is happening |
EXAMPLES:
To trace the date in the flash output window:
myCalendar.onDateClick=function(mc,eobj,robj)
{
trace(mc.date);
}
To trace the formatted date (eg 15-9-04):
myCalendar.onDateClick=function(mc,eobj,robj)
{
trace(this.formatDate(mc.date,"dd-mm-yy"));
}
To open a specific URL in a new window and pass the date as a parameter (eg: http://www.flashloaded.com/showEvent.php?date=15/9/2004)
myCalendar.onDateClick=function(mc,eobj,robj)
{
getURL("http://www.flashloaded.com/showEvent.php?"+this.formatDate(mc.date,"dd-mm-yy"), "_blank");
}
To trace the plain event content in the flash output window:
myCalendar.onDateClick=function(mc,eobj,robj)
{
trace(eobj.content);
}
To trace all plain event properties in the flash output window:
myCalendar.onDateClick=function(mc,eobj,robj)
{
for (var i in eobj) {
trace(i+": "+eobj[i]);
}
}
To trace the first recurrent event content in the flash output window:
myCalendar.onDateClick=function(mc,eobj,robj)
{
// because it is possible to have more then 1 recurrent event on the same date
// robj is returned as array of events, and we are accessing the first one by robj[0]
trace(robj[0].content);
}
To trace all recurrent event properties of the first event in the flash output window:
myCalendar.onDateClick=function(mc,eobj,robj)
{
// because it is possible to have more then 1 recurrent event on the same date
// robj is returned as array of events, and we are accessing the first one by robj[0]
for (var i in robj[0]) {
trace(i+": "+robj[0][i]);
}
}
To trace all recurrent event properties of all recurrent events in the flash output window:
myCalendar.onDateClick=function(mc,eobj,robj)
{
for (var i in robj) {
for (var j in robj[i]) {
trace(j+": "+robj[i][j])
}
}
}
Please examine calendarDemo_1.fla to see a working example of this.
Adding Year button
Adding the buttons to advance the calendar by year is easy. Simply create 2 buttons on the same timeline where the component named cal is, give them instance names prevYear and nextYear and add the following actionscript to the timeline:
nextYear.onRelease=function()
{
cal.showMonth(12)
}
prevYear.onRelease=function()
{
cal.showMonth(-12)
}
Please examine calendarDemo_3.fla to see a working example of this .