-
Pictures correlate with clock?
I want to have a script in my flash movie that takes the time from a users machine and then loads an external jpg that correlates with that time. I have different pictures for each 15 minute time increment. Is there a script that would be able to find the time on the users machine and then round up or down to a 15 minute increment (:00, :15, :30, :45) and then load a jpg for that increment (this would have to be in a 24 hour format (army time) in order to work)?
Here is an example:
The time on the user's computer is 7:38 pm. The flash would take that time and then round to the closest 15 minute increment, which would be 7:30. It would then convert this to 24 hour time, which would be 19:30. Then, there would be a variable script that would take the hour and minute and then convert that to "hour-minute.jpg" so then the loaded external jpg for this example would be "19-30.jpg".
Thanks for any help. I have worked with clock/time in flash before, but nothing like this.
-- K
-
Senior Member
This function'll do it.
Code:
function getJpegName()
{
var dat = new Date();
var hr = dat.getHours(); // this is 24-hour format already...
var mn = dat.getMinutes();
// round to most recent 15 minute boundary
mn = Math.floor(mn/15) * 15;
// OPTIONAL - add leading zeros to hr and minute
if (hr < 10)
hr = "0" + hr;
if (mn < 10)
mn = "0" + mn; // remove these last 4 lines if leading zeros not wanted
return hr + "-" + mn + ".jpg";
}
// example usage:
myName = getJpegName();
trace( myName );
-
Awesome. Thanks for the quick reply. I will try it out and get back with you... if I wanted to load the outcome external jpg into a target movieclip, how would I do that?
Thanks,
-- K
-
Senior Member
Your target movieclip needs an instance name, such as target_mc.
Then:
myName = getJpegName();
target_mc.loadMovie(myName);
Or more simply:
target_mc.loadMovie(getJpegName());
Also note that I didn't stick any kind of path name in front of the jpeg name, you might want that:
target_mc.loadMovie("/clockimages/" + getJpegName());
- jim
-
Thanks for the help. Everything works great. I knew it was a fairly easy solution.
-- K
-
Senior Member
I was thinking about this on the way to work, and thought it would be kind of funny to use this technique to make a fake webcam that broadcasts the same sequence of images every day.
Every hour, someone in the house gets shot, stabbed, or something... holds up a sign to the camera saying 'call 911' etc. etc.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|