0

我有一个动作脚本 3 代码和一个大问题:我的日历没有显示所有月份,我不知道为什么。例如,9 月份有 30 天,但我的日历只显示 26 天。所以任何帮助都会很棒!我的代码:

var daysMonth:int;//variable that holds a value of all days in the current month
var daysNumber:int;//counter for days
var weeks:Number;//variables that hold weeks of the date
var days:Number;//variables that hold current day
var year:Number;//variables that hold current year
var month:Number;//variables that hold current month
var firstDayOfMonth:Number;// variable that holds the position of first day in current month

var shapeButtonWidth:int = 35;
var shapeButtonHeight:int = 35;
var marginBetweenButtons:int = 2;
var calendarBackgroundColor:uint = 0x1e1e20;
var calendarNumberHolderColor:uint = 0x101010;
var calendarNumberTextColor:uint = 0xEAEAEA;
var dayHighlightBorderColor:uint = 0x893827;

var nowDate:Date = new Date();//get current date
days = nowDate.getDate() ;//get current day
month = nowDate.getMonth() ;//get current month
year = nowDate.getFullYear() ;//get current year

var firstDay:Date = new Date(year, month, 1);
firstDayOfMonth = firstDay.getDay();

var numberOfDays:Date = new Date(year,month , 0);
daysMonth = numberOfDays.getDate();

weeks = daysMonth/7;

if (weeks > 2)//making 5 lines in some cases when month starts with the end of the week
    weeks = 6;

for (var i:int = 1; i <= weeks; i++) { 

for (var j:int = 1; j <= 7 ; j++) {

    daysNumber++;
    if (firstDayOfMonth == 0)
        firstDayOfMonth = 7;

    var calendarBackground:Shape = new Shape();
    calendarBackground.graphics.lineStyle();
    calendarBackground.graphics.beginFill(calendarBackgroundColor,1);
    calendarBackground.graphics.drawRoundRect(0,0,shapeButtonWidth * 8, shapeButtonHeight * 6,8);
    calendarBackground.graphics.endFill();
    calendarBackground.x = stage.stageWidth / 2 - calendarBackground.width / 2;
    calendarBackground.y = stage.stageHeight / 2 - calendarBackground.height / 2;
    this.addChild(calendarBackground);
    setChildIndex(calendarBackground, 0);//set the background to have the lowest index

    if (daysNumber <= daysMonth){
        if (daysNumber >= firstDayOfMonth){
            var dayC:Shape = new Shape(); //variable of custom class 
            dayC.graphics.lineStyle();
            dayC.graphics.beginFill(calendarNumberHolderColor,1);
            dayC.graphics.drawRoundRect(0,0,shapeButtonWidth, shapeButtonHeight,8);
            dayC.graphics.endFill();
            this.addChild(dayC);

            var calendarNumbers:TextField = new TextField();
            calendarNumbers.textColor = calendarNumberTextColor;

            var myFormat:TextFormat = new TextFormat();
            myFormat.size = 16;
            calendarNumbers.defaultTextFormat = myFormat;
            this.addChild(calendarNumbers);

            calendarNumbers.text = String(daysNumber - firstDayOfMonth + 1);



            dayC.x = calendarNumbers.x =  (dayC.width + marginBetweenButtons) * (j - 1)  + calendarBackground.x + 12;
            dayC.y = calendarNumbers.y = (dayC.height + marginBetweenButtons) * (i-1) + dayC.height/2 + calendarBackground.y - 5;

            if (daysNumber < 11)
                calendarNumbers.x = dayC.x + 11;
            else
                calendarNumbers.x = dayC.x + 7;
            calendarNumbers.y = dayC.y + 5;

            if (calendarNumbers.text == String(days)){
                var borderDay:Shape = new Shape();//here we draw border around current day
                borderDay.graphics.lineStyle(4,dayHighlightBorderColor);//width and color of border around current day
                borderDay.graphics.drawRoundRect(dayC.x+1, dayC.y+1, shapeButtonWidth - 3,shapeButtonWidth - 3,8);
                borderDay.graphics.endFill();
                this.addChild(borderDay);//adding border to stage

            }
        }
    }

}

}

谢谢!

4

1 回答 1

0

您正在通过“daysNumber”检查边界,但您显示“days”,因此您显示的第 31 个单元格包含第 26 天,前 5 个单元格不会显示。请检查“天”是否在 1..daysMonth 内,而不是“天数”。

于 2012-09-08T14:08:39.553 回答