# AS3 calendar

**URL:** https://forum.kirupa.com/t/as3-calendar/283106
**Category:** flash
**Created:** [March 2, 2009, 6:57pm UTC](https://forum.kirupa.com/t/as3-calendar/283106 "2009-03-02T18:57:56Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jryans36](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jryans36](https://forum.kirupa.com/u/jryans36)
#### Post date: [March 2, 2009, 6:57pm UTC](https://forum.kirupa.com/t/as3-calendar/283106/1 "2009-03-02T18:57:56Z")

</div>

I’m trying to make a calendar in AS3, but I’m having issues with how the date class works. I can get the month and place the days into a movieclip and add them to the stage, but how can I get the movieclips to line up under the correct day, i.e Monday…

Here is what I have so far:

//get calendar in place…  
var now:Date = new Date();  
var month = now.getMonth();  
var today = now.getDate();  
var year = now.getFullYear();  
var day = now.getDay();  
trace(today);  
next\_month.buttonMode = true;  
next\_month.addEventListener(MouseEvent.CLICK, nextMonth);  
// use another Date object to find the lastdate  
var firstDate:Date = new Date(year, month, 1);  
var lastdate:Date=new Date(year, month+1, 0);  
trace("First date: " + firstDate);  
var lastday=lastdate.getDate(); // get the lastdate  
var daycount=1; // variable to keep track of days  
var weekcount:Number=0; // variable to keep track of weeks  
trace("The last day is: " + lastday);

var days:Array = [‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’];  
var months:Array=[‘January’,‘February’,‘March’,‘April’,‘May’,‘June’,‘July’,‘August’,‘September’,‘October’,‘November’,‘December’];

//month…  
month\_txt.text = months[month];  
var blocks:Array = new Array();

trace(“Tracing:” + day);

trace("Today is: " + days[day] + " "+ today + " " + months[month] + " " + year);  
trace(now);  
[//now.setDate](https://now.setDate)(daycount); // set the date object to current date  
//var weekday=now.getDay(); // find the day of the week  
//trace(weekday);  
//place blocks in a grid…  
//while(daycount\<=lastday){  
[//now.setDate](https://now.setDate)(daycount); // set the date object to current date  
//trace(weekday);  
for(var i:uint=0; i \< 5; i++) {  
for(var ii:uint=0; ii \< 7; ii++) {  
var bloc:block = new block();  
bloc.buttonMode = true;  
this.ii = ii;  
bloc.addEventListener(MouseEvent.MOUSE\_OVER, onOver);  
bloc.addEventListener(MouseEvent.MOUSE\_OUT, onOut);  
bloc.addEventListener(MouseEvent.CLICK, onClick);  
bloc.bname = “bloc\_” + daycount;  
bloc.dday = days[ii];  
addChild(bloc);  
bloc.blocBg.alpha = 0;  
trace("This is the day: " + day);  
//trace("Bloc names: " + bloc.bname);  
bloc.x = ii \* 100 + 95;  
bloc.y = i \* 100 + 95;  
bloc.origX = bloc.x;  
bloc.origY = bloc.y;  
if(daycount \<= lastday) {  
bloc.num\_txt.htmlText = daycount;  
if(daycount == today) {  
bloc.num\_txt.htmlText = “\<b\>” + daycount + “\</b\>”;  
}  
}else {  
bloc.num\_txt.htmlText = “”;  
bloc.blocBg.alpha = 90;  
}  
if(day==6){weekcount++;} // increment the weekcount  
daycount++; // increment the daycount

```
        bloc.visible = true;
        blocks.push(bloc);
        //trace(blocks.length);
        trace(bloc.dday);
    }        
}

```

//}

```
//get next month

function nextMonth(e:Event):void {
    //get current month...
    var nMonth = months[month +1];
    //set month_txt = nMonth;
    trace (nMonth);
}

//trace("this is something: " + weekday + " something else: " + now + "how many days? " + daycount);

```

function onClick(e:MouseEvent):void {  
bloc.removeEventListener(MouseEvent.MOUSE\_OUT, onOut);  
if(e.currentTarget.scaleX \>= 5) {  
bloc.removeEventListener(MouseEvent.MOUSE\_OUT, onOut);  
}

```
e.currentTarget.scaleX = 5.5;
e.currentTarget.scaleY = 2.5;
e.currentTarget.x = stage.stageWidth/2;
e.currentTarget.y = stage.stageHeight/2;
trace("This is bloc: " + e.currentTarget.bname);

```

}

function onOver(e:MouseEvent):void {  
e.currentTarget.parent.setChildIndex(e.currentTarget, e.currentTarget.parent.numChildren - 1);  
e.currentTarget.scaleX = 1.2;  
e.currentTarget.scaleY = 1.2;  
}  
function onOut(e:MouseEvent):void {  
if(e.currentTarget.scaleX \>= 5) {  
bloc.removeEventListener(MouseEvent.MOUSE\_OUT, onOut);  
}else{  
e.currentTarget.scaleX = 1;  
e.currentTarget.scaleY = 1;  
e.currentTarget.x = e.currentTarget.origX;  
e.currentTarget.y = e.currentTarget.origY;  
}  
}

any help is greatly appreciated!
