Monday, February 23, 2009

My Cool Calender

Hi Friends,
I have created this cool Calender, I saw this calender on net and thought why cant i too create it, and started creating it, there not even a single line of same code that it present on net.. :)



here is a sample of code.... enjoy :)

//Day Box
override protected function commitProperties(): void
{
workSpace.addEventListener(DragEvent.DRAG_ENTER, onDragEnterHandler);
workSpace.addEventListener(DragEvent.DRAG_DROP, onDragDropHandler);
this.addEventListener(MouseEvent.CLICK, onClickHandler);
if(_activityEventCollection.length != 0 )
{
workSpace.removeAllChildren();
for(var i: int = 0; i< _activityEventCollection.length; i++)
{
var activityEvent: ActivityEvent = _activityEventCollection.getItemAt(i) as ActivityEvent;

var activity: DayActivity = new DayActivity();
activity.doubleClickEnabled = true;
activity.addEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClickHandler)
activity.boxWidth = _boxWidth-10;
activity.activityEvent = activityEvent;
workSpace.addChild(activity);
}
}
}

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight: Number): void
{
graphics.clear();

rect.graphics.clear();
rect.graphics.beginFill(0x4A4A4A);
rect.graphics.drawRect(_left,0,_boxWidth,_boxHeight);
rect.graphics.endFill();

textField.text = _displayDate.getDate().toString();
textField.x = _left+_boxWidth-15;
textField.y = 0;

workSpace.width = _boxWidth-8;
workSpace.height = _boxHeight-16;
workSpace.setStyle("backgroundColor","WHITE");
workSpace.x = _left+4;
workSpace.y = 15;

}


//HourBox

override protected function commitProperties(): void
{
workSpace1.addEventListener(DragEvent.DRAG_ENTER, onDragEnterHandler);
workSpace2.addEventListener(DragEvent.DRAG_ENTER, onDragEnterHandler);
workSpace1.addEventListener(DragEvent.DRAG_DROP, onDragDropHandler);
workSpace2.addEventListener(DragEvent.DRAG_DROP, onDragDropHandler);
if(_enableCommitProperties)
{
_enableCommitProperties = false;
if(_activityEventCollection.length != 0 )
{
workSpace1.removeAllChildren();
workSpace2.removeAllChildren();
var temp: int = 0;
for(var i: int = 0; i< _activityEventCollection.length; i++)
{
var activityEvent: ActivityEvent = _activityEventCollection.getItemAt(i) as ActivityEvent;
if(activityEvent.startDate.getMinutes() == 0) temp++;
}
var WorkSpace1CmptWidth: Number = (temp !=0 ? ((_boxWidth-50)/temp) : (_boxWidth-50));
var WorkSpace2CmptWidth: Number = (_boxWidth-50)/(_activityEventCollection.length - temp);
workSpace1.setStyle("horizontalGap",WorkSpace1CmptWidth);
workSpace2.setStyle("horizontalGap",WorkSpace2CmptWidth);
for(i = 0; i< _activityEventCollection.length; i++)
{
activityEvent = _activityEventCollection.getItemAt(i) as ActivityEvent;
var activity: HourActivity = new HourActivity();

if(activityEvent.startDate.getMinutes() == 0)
{
activity.boxWidth = WorkSpace1CmptWidth;
activity.activityEvent = activityEvent;
workSpace1.addChild(activity);
}
else
{
activity.boxWidth = WorkSpace2CmptWidth;
activity.activityEvent = activityEvent;
workSpace2.addChild(activity);
}
}
}
}
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number): void
{
graphics.clear();

rect.graphics.clear();
rect.graphics.beginFill(0x4A4A4A);
rect.graphics.drawRect(0,_top, _boxWidth, _boxHeight);
rect.graphics.endFill();

hourTxtField.text = _hours;
hourTxtField.x = 10;
hourTxtField.y = _top;

vBox.width = _boxWidth-40;
vBox.height = _boxHeight-3;
vBox.setStyle("backgroundColor","WHITE");
vBox.x = 40;
vBox.y = _top+1;

workSpace1.width = _boxWidth-45;
workSpace1.height = (_boxHeight-3)/2;
workSpace1.setStyle("backgroundColor","WHITE");

workSpace2.width = _boxWidth-45;
workSpace2.height = (_boxHeight-3)/2;
workSpace2.setStyle("backgroundColor","WHITE");
}

//Hour Activity

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number): void
{
if(_activityEvent != null)
{
graphics.clear();

ellipse.graphics.clear();
ellipse.graphics.beginFill(_activityEvent.color);
ellipse.graphics.drawRoundRect(0, 0, _boxWidth, 17, 25);
ellipse.graphics.endFill();

activityTxt.text = _activityEvent.startDate.getHours()+":"+ _activityEvent.startDate.getMinutes()+" "+_activityEvent.activity
activityTxt.x = 0;
activityTxt.y = 0;
}
}

//DayActivity
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number): void
{
if(_activityEvent != null)
{
graphics.clear();

rect.graphics.clear();
rect.graphics.beginFill(0xFDFCFC);
rect.graphics.drawRect(0, 0, _boxWidth, 17);
rect.graphics.endFill();

activityTxt.defaultTextFormat = new TextFormat("Arial Rounded MT Bold",10,_activityEvent.color,true);
activityTxt.text = _activityEvent.startDate.getHours()+":"+ _activityEvent.startDate.getMinutes()+" "+_activityEvent.activity
activityTxt.x = 0;
activityTxt.y = 0;
}
}