Hello all, I have a clip that is masked and it is going to be a week to week calendar. I foresee a slight issue in regards to the published project being out of date once the published week is in the past. How do I move the clip based on the date so that the viewer sees the current week - and not the week that the file was originally published? I can send the fla as visual aid since it's hard to explain. (used to be able to upload file here hmm) Anyone care to take a stab? Thanks.
Hi, you can use the Date class to get the current date (taking the user's system time/date). The attached code shows how to get the passed time from the first day of the year until execution. Be aware that it starts the weeks count from the weekday of january 1st and changes the week/mc at that day (for this year it would be sunday), so you have to adjust it to the day you want. In my example every friday would increase 'weeks', what can be used for moving the MovieClip to the new entry. cheers, blemmo DAY = 5; // 0=sunday...6=saturday //today var now:Date = new Date(); //january 1st var january:Date = new Date(now.getFullYear(), 0, 1, 0, 0, 0, 0); //get milliseconds since 1970 for today and for january 1st of the same year now_ms = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds()); january_ms = Date.UTC(now.getFullYear(), 0, 1, 0, 0, 0, 0); //1000*60*60*24 ms == 1 day, +1 to show actual day days = Math.floor((now_ms-january_ms)/86400000)+1; //set the weekday to change mcs days += 6-DAY+january.getDay(); weeks = Math.floor(days/7); trace("days :"+days+" | week :"+weeks);
How about just any Event Calendar. I see a few on line - Sparks Event calendar is one - but it's not working with my version of Flash (MX 2004). Are there any out there that can have events added to easily?
Hi, well it's not so much AS, it's more a mathematics thingie. I assume you have a different MC or frame for each week, accessible through IDs like "week1", "week2" etc. Now it's the task to find out in which week the movie is played, and jump the player to that ID. Flash has the 'Date' class, which stores date objects. With that, we can get the date on which the movie is playing (in the code: var 'now'). Since there is no calendar in Flash, we get the day and month of the year, but that doesn't tell the week-number. The Date class has also a property that returns the number of Milliseconds since 1/1/1970 for a given date, UTC(). So we could take UTC() of 'now', minus the UTC() of the date of 1/1/this_year and get the time passed this year. To get the number of days out of the Milliseconds, apply the factor 86400000, and ignore every Millisecond after the dot. This is all done in days = Math.floor((now_ms-january_ms)/86400000)+1; The "+1" is because it will return 0(.xxxx...) ms for day 1, but it's actually day 1, not day 0. So now we know the number of days since 1/1, and could calculate the week in which we are. As this depends just on factor 7, the day of the week where a week changes would be the day of 1/1. To set that weekday to another day, we must add the difference to the wanted day as it's returned by Date.getDay(). Thats done in days += 6-DAY+january.getDay(); You can set DAY at the beginning of the code to the weekday where you want the display to be changed. Now we have the numbers of weeks that passed this year and can tell the player to display the entry of that week. This will change every 7 days. If you want to add events at unregular intervalls, you'd need other code beside that. blemmo
Don't see what you're looking for? Try a search.
|