Groups | Blog | Home
all groups > flash actionscript > august 2006 >

flash actionscript : Questions about Date in flash


The 350Z
8/19/2006 8:46:31 PM
Hi everyone,

I'm doing an experimental Blog now and having some difficulties about Date in
Flash.

What I'm trying to do is to seperate each months into weeks.
So let's say I want to display my blog in August. Since August has 5 weeks, I
want to display all entries in 5 different tables. Each table represents week.
So the first table will only show 6 entries, because the first week of August
begins tuesday (aug 1) and ends Sunday (Aug 6).

The second table will display 7 entries and so forth.

Is this possible?

thank you
Rothrock
8/20/2006 4:49:41 PM
Yes it is doable. Check the help filed for the Date class. There you will find
the getDay() method. This returns an integer representing the day of the week a
given date will fall upon. It starts 0 for Sunday, 1 for Monday, and so on.

So to figure out which day August 1, 2006 was you would do this:

myDate=new Date(2006,7,1)//Remember months start at 0 for Jan
startDay=myDate.getDay();
trace(startDay)//Should be 2 for Tuesday

Also a nice trick is this:

myDate=new Date(2006,7,0);

That gives you the zeroth day for August which is really the last day of July.
I'm sure you will find a million uses for that.
myIP
8/20/2006 6:02:17 PM
The code below will find the first day and last day of the month. It has trace
statements that will output a message on where to create code for these tables
and entry fields that you plan to have. I don?t know if you need to create
these tables/entries for the whole year or not, if so then you need to change
the month parameter for the Date object constructor.

var dayNames_array:Array = new Array("Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday");

var monthNames_array:Array = new Array("January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December");

var current_date:Date = new Date();
var currentYear = this.current_date.getFullYear();
var currentMonth = this.current_date.getMonth()
var currentMonthsDate = this.current_date.getDate();
var currentMonthsWeek = Math.floor(currentMonthsDate/7);
var currentDayOfWeek = this.current_date.getDay();

var firstLastDay:Date = new Date( this.currentYear,
this.currentMonth,
1);

var firstDateOfMonth = firstLastDay.getDay();//returns 2
var firstDayOfMonth = this.getDayAsString(firstDateOfMonth);//returns Tuesday
var lastDateOfMonth = findLastDateOfMonth();
var foundElementToStart = findStartingPoint(firstDayOfMonth);
var datePointer:Number = 1;

this.createEntriesAndTable(foundElementToStart);

function getDayAsString(day:Number):String
{
return this.dayNames_array[day]
}

function getMonthAsString(month:Number):String
{
return monthNames_array[month];
}

function findLastDateOfMonth():Number
{
for(var i=27; i<=35; i++)
{
this.firstLastDay.setDate(i);
//trace(this.firstLastDay.getDate());

if(firstLastDay.getDate() < i)
{
return i-1;
break;
}
}
}

function findStartingPoint(firstDayOfMonth):Number
{
var foundElement:Number;

for(var i=0; i<=this.dayNames_array.length; i++)
{
findingElement = this.dayNames_array[i];

if(findingElement == firstDayOfMonth)
{
foundElement = i;
return foundElement;
break;
}
}
}

function createEntriesAndTable(elementToStart:Number)
{
trace("need code to create table here");
var dayNamesArrayLength = this.dayNames_array.length;

for(elementToStart; elementToStart<=dayNamesArrayLength; elementToStart++)
{
if(this.datePointer == this.lastDateOfMonth){
trace("need code to create an entry field for the "+this.datePointer+" day
which is a "+dayNames_array[elementToStart]+".");
break;
}else if(dayNamesArrayLength == elementToStart){
//trace("need code to create an entry field for the "+this.datePointer+"
day");
createEntriesAndTable(0);
}else
trace("need code to create an entry field for the "+this.datePointer+" day
which is a "+dayNames_array[elementToStart]+".");
this.datePointer++;
}
}

//trace("This is the current month >>> "+this.getMonthAsString(currentMonth));
//trace("This is the current week >>> "+this.currentMonthsWeek);
//trace("This is the current day >>>
"+this.getDayAsString(currentDayOfWeek));
//trace("This is the current date >>> "+this.currentMonthsDate);
trace("________________________________________________");
trace("The first day of this month was >>>
"+this.getDayAsString(firstDateOfMonth));
trace("The last date of this month is >>> "+lastDateOfMonth);
The 350Z
8/21/2006 8:24:14 PM
Oh thanks alot guys!!
I'm sorry for such a late reply, I was away for a fewdays without a computer.

AddThis Social Bookmark Button