Home  >  

Calendar Component in ActionScript 3 Part 3

Author photo
AddThis Social Bookmark Button

So far we've seen how to implement the calendar component, and explored the logic inside the Calendar class itself. From here I will show the logic inside of the Day class, and talk about potential ways to expand the component.

When I first created the Day class I named it AbstractDay because I had a number of ways that I wanted to extend it for my own uses. When I open sourced the project I wanted to have a default state for the component, so anyone could just use it as is, so rather than willfully instantiate an abstract class I just renamed it and made it the default.

With that in mind, the Day class simply has a drawDay function that draws a rectangle and has a TextField to show the date.

public class Day extends Sprite implements ICalendarItem
{
 private var _name:String;
 private var _myDate:Date;
 private var _events:Array;
 private var _dayNumber:Number;
 private var _display:TextField
 private var _stackIndex:Number
 private var _isActive:Boolean = false;
 private var _restingX:Number;
 private var _restingY:Number;
 		
 public var activateTweenH:Tween;
 public var activateTweenW:Tween;
 public var activateTweenT:Tween;
 public var activateTweenL:Tween;
 		
 public function Day()
 {
   super();
   _display = new TextField()
   _display.height=20
   _display.width=20
   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();
   var filter:DropShadowFilter = new DropShadowFilter();
   this.filters = [filter]         
 }

Future Expansion

If you've checked out the project or explored the source files at all you'll notice there are two interfaces in the project: ICalendarItem, and ICalendar.

ICalendarItem I created with the hopes of allowing the Calendar to draw itself with items other than Days, and to potentially incorporate controls like buttons or multi-select boxes inside of Days.

In my own projects I've extended the Day class to create Days that read in an XML feed of television listing data to allow users to browse what's on TV for any given day. All of the business logic for that was inside of the derived Day object and the Calendar simply drew itself as it normally would, decoupled from whatever the Day was doing.

ICalendar I created because I eventually wanted to have a CalendarController (which I stubbed out in the project as well) that would allow the user to navigate through different months.

It was my intention to have both the Calendar and CalendarController implement this interface, and either could be instantiated and used almost interchangeably. The CalendarController would have a Calendar object through composition and would delegate calls to ithe Calendar class through that object.

In Closing

I originally made this component publicly available so that anyone could use it, but I open sourced it so that anyone could take it and build upon it for their own purposes. I hope that this component is useful to you in some way, but I would really love to return to the project a few months from now and see branches created by you, with derived and new classes created to do all sorts of things that I hadn't even thought of.

Read more from Tom Barker. Tom Barker's Atom feed

Comments

1 Comments

If I have to say some thing about this site is:
Superb

cisco certification

Leave a comment


Tag Cloud

Poll: Mobile Features

What feature do you use most on your mobile phone?

Vote | View Poll Results | Read Related Blog Entry

Latest Features

Recommended for You

@InsideRIA on Twitter

Archives

  • Or, visit our complete archive.  

About This Site

Welcome to the premiere community site for all things RIA sponsored by O'Reilly Media and Adobe Systems Incorporated.