Results 1 to 2 of 2

Thread: Displaying Date/Time in Flash MX

  1. #1

    Displaying Date/Time in Flash MX

    Ok now this is not the easiest way of doing this in Flash Mx but it does use the new switch function so thought would let everyone see it
    original tut is at -> http://www.actionscript.org/tutorial...me/index.shtml

    thought I would rewrite it to make it a bit easier to understand and also add some extra functionality to it......

    ok so lets start your new movie ::::

    first create a new movieclip called date_mc - this will hold your actual display so in it create a dynamic text box called date_txt

    set the proporties (text font/color etc) and then name it as date_txt - this is done in the proporties menu were it says var

    ok now still in your date_mc create a new keyframe on frame 2 - change the date_txt's name in this frame (not first one) to date_txt2

    ok now drag an instance of this movieclip onto the main timeline - give it an instance name of date_mc

    ok almost done now just to make our button - create a new layer above the one holding date_mc and use the fill rectangle tool to draw a large rectangle covering your date_mc - set line to off and pick any color you wish - doesn't matter wont be seen.

    Now select the rectangle and convert it to a button (press F8 in windows) called date_btn - now set its instance name to the same (date_btn) and then change its alpha (in proporties menu) to 0% so is invisible

    ok now for the code ::::

    in the date_mc movieclip insert a stop action on frame 1 like so
    stop();
    and then on your main timeline create a new layer called actions and insert this code :::

    Code:
    function howlong(arg) {
    	if (length(arg)==1) {
    		arg = "0" + arg;
    		return arg;
    		}
    	else {
    		arg = arg;
    		return arg;
    		}
    	}
    myDate = new Date();
    
    hr = howlong(String(myDate.getHours()));
    mnt = howlong(String(myDate.getMinutes()));
    
    daytext = myDate.getDay();
    dd = myDate.getDate();
    mm = myDate.getMonth();
    yyyy = myDate.getFullYear();
    
    switch (daytext) {
    	case 0:	daytext = "Sunday";
    			break;
    	case 1:	daytext = "Monday";
    			break;
    	case 2:	daytext = "Tuesday";
    			break;
    	case 3:	daytext = "Wednesday";
    			break;
    	case 4:	daytext = "Thursday";
    			break		
    	case 5:	daytext = "Friday";
    			break;
    	case 6:	daytext = "Saturday";
    			break
    	}
    
    switch (mm) {
    	case 0:		mm = "January";
    				break;
    	case 1:		mm = "February";
    				break;
    	case 2:		mm = "March";
    				break;
    	case 3:		mm = "April";
    				break;
    	case 4:		mm = "May";
    				break		
    	case 5:		mm = "June";
    				break;
    	case 6:		mm = "July";
    				break
    	case 7:		mm = "August";
    				break
    	case 8:		mm = "September";
    				break
    	case 9:		mm = "October";
    				break
    	case 10:	mm = "November";
    				break
    	case 11:	mm = "December";
    				break
    	}
    
    
    _root.date_mc.date_txt = (hr + ":" + mnt)
    _root.date_mc.date_txt2 = (daytext + "," + dd + " " + mm + " " + yyyy)
    
    date_btn.onRollOver = function(){
    	_root.date_mc.gotoAndStop(2);
    }
    date_btn.onRollOut = function(){
    	_root.date_mc.gotoAndStop(1);
    }
    ok the code is pretty much self explanitary - and is explained here -> http://www.actionscript.org/tutorial...me/index.shtml

    but i will go over the changes i made ::: the last part

    Code:
    _root.date_mc.date_txt = (hr + ":" + mnt)
    _root.date_mc.date_txt2 = (daytext + "," + dd + " " + mm + " " + yyyy)
    
    date_btn.onRollOver = function(){
    	_root.date_mc.gotoAndStop(2);
    }
    date_btn.onRollOut = function(){
    	_root.date_mc.gotoAndStop(1);
    }
    as you can see the original tut just had a static display showing date/time - now i have altered it so that time is displayed until you mouseover and then it switches to date - this is easily done

    the first 2 lines assign the values to the 2 different txt fields
    then the button actions tell it which frame in date_mc to look at - now because the different txt fields are on different frames only one is visible either date/time

    could also have been done using visible = false;

    eg ::::

    Code:
    date_btn.onRollOver = function(){
    	date_txt._visible = false;
    	date_txt2._visible = true;
    }
    but i like to keep everything neatly in its own movieclips

    v_Ln

  2. #2
    This is a nice tutorial, i enjoyed reading.

    The FACT that people ignore FACTS
    doesnt mean that FACTS are not FACTS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •