archive: April 2009


24-hour Flash Loop

Posted by Shane

I told you I get back to this! For the past week, myself and the original author of the gradient tween, Steve on FlashDen, did a few series of emails to figure out how to implement a 24-hour loop with allowing the user to “start” the tween at any point.

So I already had my XML file defining the color blocks for the different times: Night Time, Dawn, Sunrise, Day (Morning and Afternoon), Dusk, Sunset, and Twilight. I also how long the duration was for considering that once we start the loops, we don’t want it going to fast or too slow. We needed it setup just right so it happened in the amount of the hours that the block was designed for.

So with all that work done… I had to define in the Action Script code the block number based on the current hour.

//    Dawn - 1 hours 06:00am to 06:59am
if ( (hour > 5)  AND (hour < 7) AND (!isBlockSet()) )
blocknum = 1;
blockstarthour = 6;
blockendhour = 7;
blockset = true;

The code allowed us to figure out  where in the duration that we should start. Using the current hour, the max hour, and the current minutes we can figure out the number of minutes left and then find out the fraction of time remaining. Just the fraction.

var blockMinutes:Number  = (blockendhour - blockstarthour) * 60;
var minsPassed:Number = ((hour - blockstarthour) * 60) + mins;
var fraction:Number = minsPassed/blockMinutes;

Since we know what XML time block we are going to, we just add that to the fraction (1 + 0.5) and when we plug that into the gradient action script file we get the exact “look” for that time period (or in this example 6:30am – Time Block #1 and we are going 50% into it). And.. tada! We now have the current time’s look in the header. So if you were to keep the flash file open for 24 hours and watch it for that long, you would see the “sky” do exactly do what it is supposed to do now:  Night Time, Dawn, Sunrise, Day (Morning and Afternoon), Dusk, Sunset, and Twilight

I posted the example SWF here, this time with the hills that will lie at the bottom. Expect to see the flash file running very soon! I’ll be adding the flash loader and the rabbit to it very soon. Then the major parts will come together over the next few weeks.

Comments 0

Commenting is closed

No Comments Yet