I have 3 movies clips one of the moring sun, one of a afternoon park and one of the nighlife. I would like it so when say its bout 6am til 1pm, it would show the morning, then 1pm to 7pm the afternoon then 7pm to 6am the evening. Could someone show me how is this is done as I don't know how :S Thanks for your time Jason
There is a fairly simple way to do this, and it is based on your system clock. Basically, you ask Flash to retrieve information from your system clock and put that information into your movie. If you want more details, rather than taking forever explaining it, there is an example in your program files. Go to C://program files/macromedia/flash mx/samples. From there, you can view the SWF sample, Clock with Flash player, and then find the corresponding FLA sample and study the script contained in it. I hope this helps you with your problem, T-Juice-T
Hi, Flash has a Date() object that can be used to get all sorts of information about the current date and time. Look it up in the reference. Here's a bit of code that you could use to achieve what you want. Replace the statements in the 'if' statements to swap out the different clips. //Get the number of hours (0 - 23) using the Date class, //and store it in a new variable 'timeOfDay' var timeOfDay:Number = new Date().getHours(); //Use if statements to set the movie clip in each case: trace(timeOfDay); if (timeOfDay < 6 or timeOfDay >= 7) { //show night trace("it is night-time"); } else if (timeOfDay >=6 and timeOfDay < 1) { //show morning trace("it is morning"); } else if (timeOfDay >=1 and timeOfDay < 7) { //show afternoon trace("it is afternoon"); }
Put the three movieclips on their own layers, for convenience, position each one, where you want it to be when it appears. Give the clips the instance names: morning_clip,afternoon_clip, and evening_clip. Then, put the following code on the frmae that holds them: updateTimeClip(); update_id = setInterval(updateTimeClip,1000*60); function display_mc(mc){ afternoon_clip._visible = false; morning_clip._visible = false; evening_clip._visible = false; mc._visible = true; } function updateTimeClip(){ //Get the number of hours (0 - 23) using the Date class, //and store it in a new variable 'timeOfDay' var timeOfDay:Number = new Date().getHours()+1; //Use if statements to set the movie clip in each case: if ((timeOfDay >= 6) && (timeOfDay<13)) { //show morning trace("it is morning-time"); display_mc(morning_clip); } else if ((timeOfDay >=13) && (timeOfDay < 19)) { //show afternoon trace("it is afternoon"); display_mc(afternoon_clip); } else if ((timeOfDay >=19) || (timeOfDay < 6)) { //show evening trace("it is evening-time"); display_mc(evening_clip); } }
wow it works!! but wht happens if the user has a 12-hour clock? will it work still? Thanks for your time
Flash uses 24 hours to incorporate AM and PM. If the user has a 12 hour clock (I don't know a user without a 12 hour clock), anything in the pm, is 11+, but 23 is 12 midnight. (I added 1 to to the getHours to get 1 thru 24.) Look up: Date.getHours method in the HelpDocs
im sure im doing something wrong, but when I put '1+' to make it 1pm, it comes up with this error: Operator '+' must be followed by an operand if ((timeOfDay >= 6) && (timeOfDay<1+)) { Thanks for your time Jason
Don't see what you're looking for? Try a search.
|