+ Reply to Thread
Results 1 to 2 of 2

How to create a clock using Flash CS3 and PHP - second part

This is a discussion on How to create a clock using Flash CS3 and PHP - second part within the Tutorials forums, part of the Flash English category; This is the second part of this tutorial . We can say that most of the work has been done ...

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,762
    Rep Power
    11

    How to create a clock using Flash CS3 and PHP - second part

    This is the second part of this tutorial .
    We can say that most of the work has been done in the preceding article: How to create a clock ? first part where we saw how to format the universal time passed by the PHP script.
    Today, we will see how to increase the time taken from the server so to obtain a digital clock complete of the date. Follow me?

    Following the logic, what would you think if we would increase the date returned by the server of one unit per second using the Timer Class?

    Let?s open the Orario.as and at line 63, instead of calling the function initTime() only once, we will call it more times using a Timer.
    So let?s renamed the call initTime as callInitTime().
    At this point I create a new function called, as you could guess, callInitTime,
    Code:
    private function callInitTime():void
    {
    	var timer:Timer=new Timer(1000,0);
    	timer.addEventListener(TimerEvent.TIMER,initTime);
    	timer.start();
    }
    now, we are calling the function initTime, once per second using the Timer.
    We only have to increase the value of the variable serverTime of one unit each time, the following way:
    Code:
    serverTime++;
    The value of serverTime (returned by the server) will be increased of one second, as it would happen in a clock.

    The new Orario.as would be as follow:
    Code:
    package
    {
    	import flash.display.MovieClip;
    	import flash.text.TextField;
    	import flash.net.URLLoader;
    	import flash.net.URLRequest;
    	import flash.net.URLVariables;
    	import flash.net.navigateToURL;
    	import flash.utils.Timer;
    	import flash.events.*;
    	
    	public class Orario2 extends MovieClip
    	{
    		private var days_array:Array;
    		private var months_array:Array;
    		
    		private var serverTime:Number;
    		
    		public function Orario2()
    		{
    			init();
    		}
    		
    		private function init():void
    		{
    			days_array=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday',
    									'Friday','Saturday');
    			months_array=new Array('JANUARY','FEBRUARY','MARCH','APRIL',
    									'MAY','JUNE','JULY','AUGUST','SEPTEMBER','OCTOBER',
    									'NOVEMBER','DECEMBER');
    			
    			callServer();
    		}
    		
    		private function callServer():void
    		{
    			var richiesta:URLRequest=new URLRequest();
    			richiesta.url='http://www.flepstudio.org/gettime.php';
    			var loader:URLLoader=new URLLoader();
    			addListeners(loader);
    			try 
    			{
    				loader.load(richiesta);
    			} 
    			catch (error:Error) 
    			{
    				trace('Unable to load requested document.');
    			}
    		}
    		
    		private function addListeners(d:IEventDispatcher):void
    		{
    			d.addEventListener(Event.COMPLETE,completato);
    		}
    		
    		private function completato(e:Event):void
    		{
    			var loader:URLLoader=URLLoader(e.target);
    			var vars:URLVariables=new URLVariables(loader.data);
    			serverTime=vars.time;
    			
    			callInitTime();
    		}
    		
    		private function callInitTime():void
    		{
    			var timer:Timer=new Timer(1000,0);
    			timer.addEventListener(TimerEvent.TIMER,initTime);
    			timer.start();
    		}
    		
    		private function initTime(t:TimerEvent):void
    		{
    			var server_milliseconds:Number=serverTime*1000;
    			
    			var real_date:Date=new Date(server_milliseconds);
    			
    			var hours:int=real_date.getHours();
    			var minutes:int=real_date.getMinutes();
    			var seconds:int=real_date.getSeconds();
    			var day_of_the_week:String=days_array[real_date.getDay()];
    			var day:int=real_date.getDate();
    			var month:String=months_array[real_date.getMonth()];
    			var year:int=real_date.getFullYear();
    			
    			var hours_str:String=hours.toString();
    			if(hours<10)
    				hours_str='0'+hours.toString();
    			var minutes_str:String=minutes.toString();
    			if(minutes<10)
    				minutes_str='0'+minutes.toString();
    			var seconds_str:String=seconds.toString();
    			if(seconds<10)
    				seconds_str='0'+seconds.toString();
    			
    			format_txt.text=hours_str+':'+minutes_str+':'+seconds_str+'\n'+
    			day_of_the_week+' '+day+' '+month+'\n'+year;
    			
    			serverTime++;
    		}
    	}
    }
    Here is the result:





    The next step will be to add the choice of time zone to our clock.

  2. #2
    Junior Member Settled In cpdavidd is on a distinguished road
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Re: How to create a clock using Flash CS3 and PHP - second part

    Hello,

    Nice tutorial! :) But when will be writed the third part of tutorial?

+ Reply to Thread

Similar Threads

  1. Replies: 52
    Last Post: 19-09-11, 18:05
  2. Analogue clock
    By Flep in forum FlepStudio utilities
    Replies: 9
    Last Post: 09-03-11, 10:06
  3. Create Library book system for Flash PHP
    By clonez in forum Flash CS3 | PHP | mySQL
    Replies: 0
    Last Post: 21-10-08, 15:11
  4. Prevent clock refreshing
    By conolan in forum HELP free utilities
    Replies: 1
    Last Post: 28-05-08, 21:09
  5. Replies: 0
    Last Post: 25-09-07, 16:32

Tags for this Thread

Bookmarks

Posting Permissions

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