PDA

View Full Version : Time controlled pictures..



dgnara
05-01-2007, 04:14 AM
ok here is my prob..

I need an image to change when the time does.. there are radio program picts, so lets say the morning show is from 6 to 9 thats one graphic.. pic1
then from 9:01 to 2 is the fire your boss one.. so that would be pic2
then angela from 2:01 to 7pm thats pic3 and so on till it goes back to morning show..

honestely I have no idea where to even start with the actionscript..
All HELP needed and appreciated!!:D

djr33
05-01-2007, 06:35 AM
No clue on the specific action script, but this is fairly easy.

if (time < 8) { graphic = 1.jpg; }
else if (time < 11) { graphic = 2.jpg; }
else if (time < 18) { graphic = 3.jpg; }
else { graphic =4.jpg; }

Just find out the exact way you'd need to code it (just looking up functions; shouldn't be too hard), and use that idea.
graphic is the image you're using, so not sure if that's exactly how you'd change it, but you get the idea, and time is a variable for the current time... you'd need to set that.

nwalton
05-01-2007, 08:25 AM
Does the movie need to load these images when someone pulls up the page at a certain time of day? I've used PHP before to get the timestamp when a page loads, and then passed the variable to Flash using the swfobject implementation (http://blog.deconcept.com/swfobject/). I can go into more detail if you need me to (it's kind of late or I would right now).

nwalton
05-01-2007, 07:43 PM
Ok. Here's what I've done. This would be in a "filename.php" file on a server that supports PHP:


<head>
...
<script type="text/javascript" src="swfobject.js"></script>
</head>


<html>
<body>
<?php
$hour = date('g');
?>

<div id="flashOutput">
<!-- This is where your flash movie gets inserted. This content will be replaced -->
</div>

<script type="text/javascript">
var so = new SWFObject("myswf.swf", "output", "550", "200", "8", "#ffffff");
so.addVariable("time", "<?php echo($hour)?>");
so.write("flashOutput");
</script>

...
</body>
</html>

The swfobject stuff is what I use to include my swf movies. It works well, so I've included it. This code assumes that the swfobject.js (http://blog.deconcept.com/swfobject/swfobject.zip) file is in your directory.

The php code to get the hour of the day is in blue. It's passed (by the javascript) to the swf using the Flashvars object, which is used to pass variables from web pages to Flash movies. The variable "hour" will be avalable on frame 1 of your movie, even though you've never declared it there. Then you can use that variable to find and load the correct image, as djr33 noted above.

djr33
05-01-2007, 08:17 PM
Shouldn't there also be some fallback in case javascript is disabled in the browser?

nwalton
05-01-2007, 08:24 PM
The fallback is whatever you place inside the <div> that you've specified for replacement. It holds the alternate content, and only gets replaced if javascript is enabled and the flash plugin is there. It makes for nice, silent failure of the flash content, especially if you've got a decent alternative in that div.

boogyman
05-01-2007, 08:26 PM
Shouldn't there also be some fallback in case javascript is disabled in the browser?

I agree... add this code below


<noscript>
<p>You have disabled Javascript, which is required on this website to function optimally. Please check your settings and enable Javascript then reload(refresh) your browser</p>
</noscript>

dgnara
05-02-2007, 01:24 AM
Does the movie need to load these images when someone pulls up the page at a certain time of day? I've used PHP before to get the timestamp when a page loads, and then passed the variable to Flash using the swfobject implementation (http://blog.deconcept.com/swfobject/). I can go into more detail if you need me to (it's kind of late or I would right now).
yes it would need to download the image depending on what time of day is..
the actual site is www.heymix.com

djr33
05-02-2007, 01:29 AM
The javascript is just seeding the time, so I meant that there should be a default image if there were no time supplied to the Actionscript, not that there needs to be a "javascript disabled" warning.

dgnara
05-02-2007, 01:42 AM
Ok am a little confused.. hehe..
I put Actionscript in the flash file (my swf) on the timeline.. with the IF and ELSE statements..

then on my html file I write: under the <div> tag
<noscript>
<p>You have disabled Javascript, which is required on this website to function optimally. Please check your settings and enable Javascript then reload(refresh) your browser</p>
</noscript>

Also need to make sure I have the "swfobject.js" on the same folder as my html and the "filename.php" on the php server..

Ok, I know it might seem dumb, but I dont have much experience with AS or programing (none).. a friend of mine did the php on that site.. I am more thatn willing to learn thou..

Thanks so much for helping me.. and please bear with me :D

dgnara
05-03-2007, 11:47 PM
//creates an empty movie clip to save the place for the images that will be loaded
this.createEmptyMovieClip("image_mc", this.getNextHighestDepth());
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {

//this variable places the image where it needs to be
var image_mc = image_mc._x = 580;
};
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);

var now_date:Date = new Date();
var currentHour:Number = now_date.getHours();
// if the current hour is less than 9AM...
if (currentHour <6 ) {
trace("MPod");
image_mcl.loadClip("imager5.png",image_mc);
// else..if the current hour is less than 2PM...
} else if (currentHour < 13) {
trace("Rooney and Moon in the morning");
image_mcl.loadClip("image1.png", image_mc);
// else..if the current hour is less than 2PM...
} else if (currentHour < 13) {
trace("Bill");
image_mcl.loadClip("imager2.png", image_mc);
// else..if the current hour is less than 7PM...
} else if (currentHour < 20) {
trace("Angela");
image_mcl.loadClip("image3.png",image_mc);
// else..if the current hour is less than 9PM...
} else if (currentHour < 21) {
trace("Best of Rooney Moon");
image_mcl.loadClip("image1.png", image_mc);
// else the current hour is between 9PM and 11:59PM
} else {
trace("DJ KC");
image_mcl.loadClip("image4.png", image_mc);
}

//dont forget to export images used for actions script on the linking menu (on the library)


That is my final code.. thank you so much everyone!!
I couldnt done it without you..

:)
Nara

Its on the banner on www.heymix.com the part that says ON AIR NOW.. it changes according to the hr of day!

dgnara
05-13-2007, 08:54 PM
Hmm... I was totaly happy about this code until I found out it needs to have a diferent schedules on saturday and sunday..

would anyone tell me how to implement the getDay(): on the above code??

Thanks again..

dgnara