<?xml version="1.0" encoding="utf-8"?> <mx:Application creationComplete="init()" height="400" layout="absolute" minHeight="400" minWidth="600" width="100%" xmlns:mx="">
<mx:Script> <![CDATA[ import mx.controls.Alert; import mx.controls.Text; private var offset:int = 10; private function init():void { drawM(0); drawM(1); } private function drawM(m:int): void{ var d:Date = new Date(2011,m,2); var wd:int = d.getDay(); var start:int = 1; var end:int = 30; var y:int = d.getFullYear(); switch (m + 1) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: end = 31; break; case 4: case 6: case 9: case 11: end = 30; break; case 2: if (y % 4 == 0 && y % 100 != 0) { end = 29; } else { end = 28; } } //canv.width = end * 20 + 10;
var cy:Canvas = new Canvas(); cy.setStyle("backgroundColor", "#6e6eff"); cy.setStyle("borderStyle", "solid"); cy.x = offset; cy.y = canv.y; cy.width = end * 20; cy.height = 20; var txt:Text = new Text(); txt.text = y + "年" + (m + 1) + "月"; cy.addChild(txt); canv.addChild(cy); var weekCnt:int = 1; for (var i:int = 1; i <= end; i++) { var t1:Date = new Date(y, m, i); var w:int = t1.getDay(); var strW:String = getW(w); // weed calc
if(w == 0 && i != 1){ weekCnt ++; // week width
var weekWidth:int = 0; var endWeekDay:int = 6; if(i + 6 > end){ endWeekDay = end - i - 1; //Alert.show("haha" + i);
} weekWidth = 20 + endWeekDay * 20; var cweek:Canvas = new Canvas(); cweek.setStyle("backgroundColor", "#eeee6e"); cweek.setStyle("borderStyle", "solid"); var txt2:Text = new Text(); txt2.text = "第"+weekCnt+"周"; txt2.width = weekWidth; cweek.addChild(txt2); cweek.x = offset + i * 20; cweek.y = canv.y + cy.height; cweek.width = weekWidth; cweek.height = 20; cweek.horizontalScrollPolicy = "off"; cweek.verticalScrollPolicy = "off"; canv.addChild(cweek); } if(i == 1){ // week width
var weekWidth1:int = (w + 1) * 20 + (6-w) * 20; weekWidth1 = (w + 1) * 20 + (6-w) * 20; var cweek1:Canvas = new Canvas(); cweek1.setStyle("backgroundColor", "#fefe6e"); cweek1.setStyle("borderStyle", "solid"); var txt1:Text = new Text(); txt1.text = "第1周"; cweek1.addChild(txt1); cweek1.x = offset; cweek1.y = canv.y + cy.height; cweek1.width = weekWidth1; cweek1.height = 20; canv.addChild(cweek1); } var txtDate:Text = new Text(); txtDate.text = i + ""; var dateC:Canvas = new Canvas(); dateC.width = 20; dateC.height = 20; dateC.setStyle("borderStyle", "solid"); dateC.x = 20 * (i - 1) + offset; dateC.y = canv.y + 40; dateC.addChild(txtDate); canv.addChild(dateC); var txtWD:Text = new Text(); txtWD.text = strW; var dateW:Canvas = new Canvas(); dateW.width = 20; dateW.height = 20; dateW.setStyle("borderStyle", "solid"); dateW.x = 20 * (i - 1) + offset ; dateW.y = canv.y + 40 + dateC.height; dateW.addChild(txtWD); canv.addChild(dateW); } offset += cy.width; } private function getW(i:int):String { if (i == 0) { return "日"; } else if (i == 1) { return "一"; } else if (i == 2) { return "二"; } else if (i == 3) { return "三"; } else if (i == 4) { return "四"; } else if (i == 5) { return "五"; } else { return "六"; } } ]]> </mx:Script>
<mx:Canvas backgroundColor="#FFFFFF" borderStyle="solid" height="100%" id="canv" width="100%" x="10" y="10"> </mx:Canvas>
</mx:Application>
|
阅读(830) | 评论(0) | 转发(0) |