Wednesday, August 6, 2008

Code Review Vol. 2 - Day Class, used with Calendar in ActionScript 3.0

For the sake of completion, and because I'm too exhausted from teaching late last night and getting up at 5:30 this morning to really walk through yesterday's code review, here is the source for the Day class. Again, I pared it down from its actual implementation, took out the tweens, events and filters, as well as the custom business logic and the interface that it implements. The idea of the calendar is to be a collection of Day objects, and depending on the aim of the calendar, the Day objects can be extended to do almost anything. I've made derived classes from this base class that tweened open when clicked on. Others that pull data from REST services.



import flash.display.Sprite;
import flash.text.TextField;

public class Day extends Sprite
{
private var _name:String;
private var _myDate:Date;
private var _dayNumber:Number;
private var _display:TextField

public function Day(h:Number, w:Number)
{
super();
_display = new TextField()
_display.height=h
_display.width=w
addChild(_display)
}

public function drawDay(bgColor:uint, borderSize:uint,
borderColor:uint, dayWidth:Number,
dayHeight:Number):void
{
graphics.beginFill(bgColor);
graphics.lineStyle(borderSize, borderColor,50);
graphics.drawRect(0, 0, dayWidth, dayHeight);
graphics.endFill();
}



public function getName():String
{
return _name;
}

public function getDayNumber():Number
{
return _dayNumber;
}

public function getDate():Date
{
return _myDate;
}

public function setDayNumber(dnum:Number):void
{
_dayNumber = dnum;
}

public function setName(name:String):void
{
_name = name
}

public function setDate(date:Date):void
{
_myDate = date
}


public function setDisplay(txt:String):void
{
_display.text = txt;
}


}
}

1 comment:

Anonymous said...

FRIST!