AS3 calendar

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(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(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!