Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 1 of 1

Thread: Date class of Actionscript 3.0

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

    Date class of Actionscript 3.0

    amazing Flash templates

    In this tutorial we'll see how to work with the Date class of Actionscript 3.0.

    It 'a very large class with many methods and properties so I made two good examples that we draw near to

    solutions / applications that need to retrieve the data from the user's machine.


    The first example works with time, more precisely with hours.

    Retrieving the current time on the user's machine, according to the hours I can handle the action to my SWF.

    In this case, the actions will be based on nightly or daily hours.

    So I created a MovieClip on the stage with a tween shape between two images (one at night and one at day).

    We will move the timeline of this MovieClip based on the current time.


    The second example instead works on four seasons of the year.

    So we'll move the timeline of a MovieClip based on the current date that we get by the user's machine.


    Example 1 ( try to change the time of your computer )









    The code I used + explanation comments:


    Code:
    // Package declaration
    package
    {
    	// Import the necessary classes
    	import flash.display.*;
    	import flash.text.*;
    	import flash.events.*;
    	
    	// Declare the class that extends the MovieClip and assign it 
    	// as Document Class of FLA file
    	public class Hours extends MovieClip
    	{
    		// Constant type int with value of hours that start the day
    		private const DAY_START:int=7;
    		// Constant type int with value of hours that finish the day
    		private const DAY_END:int=19;
    		// Variable type Date that will get the date from user's machine
    		private var my_date:Date;
    		
    		// Contructor declaration
    		public function Hours()
    		{
    			// Adding the ADDED_TO_STAGE event that calls the init function 
    			// ( this is useful if you want load this SWF into another without lose the root )
    			addEventListener(Event.ADDED_TO_STAGE,init);
    		}
    		
    		private function init(evt:Event):void
    		{
    			// Remove the ADDED_TO_STAGE event
    			removeEventListener(Event.ADDED_TO_STAGE,init);
    			// Instance a new Date.
    			// At this moment, Flash creates a new date based on user's machine date.
    			my_date=new Date();
    			
    			checkDate();
    		}
    		
    		private function checkDate():void
    		{
    			// Get the value of the hours ( 0-24 )
    			var now:Number=my_date.getHours();
    			// Check the hours
    			if(now > DAY_START && now < DAY_END)
    				// If the hours are greater than DAY_START and less than DAY_END,
    				// so if it is a number between 7 and 19
    				// move the city_mc timeline to frame 2
    				city_mc.gotoAndPlay(2);
    			else
    				// If not, move the city_mc timeline to frame 32
    				city_mc.gotoAndPlay(32);
    		}
    	}
    }

    Example 2 ( try to change date of your computer )









    The code I used + explanation comments:


    Code:
    // Package declaration
    package
    {
    	// Import the necessary classes
    	import flash.display.*;
    	import flash.text.*;
    	import flash.events.*;
    	
    	// Declare the class that extends the MovieClip and assign it 
    	// as Document Class of FLA file
    	public class Seasons extends MovieClip
    	{
    		// Declare the constants that represent the 
    		// 4 months of the beginning of each season
    		private const SPRING:int=3;
    		private const SUMMER:int=6;
    		private const AUTUMN:int=9;
    		private const WINTER:int=12;
    		// Variabile type Date that will get the date from user's machine
    		private var my_date:Date;
    		
    		// Dichiaro la funzione costruttrice
    		public function Seasons()
    		{
    			// Adding the ADDED_TO_STAGE event that calls the init function 
    			// ( this is useful if you want load this SWF into another without lose the root )
    			addEventListener(Event.ADDED_TO_STAGE,init);
    		}
    		
    		private function init(evt:Event):void
    		{
    			// Remove the ADDED_TO_STAGE event
    			removeEventListener(Event.ADDED_TO_STAGE,init);
    			// Instance a new Date.
    			// At this moment, Flash creates a new date based on user's machine date.
    			my_date=new Date();
    			
    			checkDate();
    		}
    		
    		private function checkDate():void
    		{
    			// I get the month from my_date and add 1 because
    			// months in Actionscript have a range of 0-11
    			var month:Number=my_date.getMonth()+1;
    			// I get the day of the month ( from 1 to 31 )
    			var day:Number=my_date.getDate();
    			// Check month and day
    			// If month is less than SPRING
    			if(monthSPRING)
    			{
    				seasons_mc.gotoAndStop(1);
    			}
    			if(month==SUMMER)
    			{
    				if(day<21)
    					seasons_mc.gotoAndStop(1);
    				else
    					seasons_mc.gotoAndStop(2);
    			}
    			
    			if(monthSUMMER)
    			{
    				seasons_mc.gotoAndStop(2);
    			}
    			if(month==AUTUMN)
    			{
    				if(day<21)
    					seasons_mc.gotoAndStop(2);
    				else
    					seasons_mc.gotoAndStop(3);
    			}
    			
    			if(monthAUTUMN)
    			{
    				seasons_mc.gotoAndStop(3);
    			}
    			if(month==WINTER)
    			{
    				if(day<21)
    					seasons_mc.gotoAndStop(3);
    				else
    					seasons_mc.gotoAndStop(4);
    			}
    		}
    	}
    }
    Attached Files

+ Reply to Thread

Similar Threads

  1. Replies: 77
    Last Post: 09-01-10, 11:11
  2. La classe Date di Actionscript 3.0
    By Flep in forum Articoli e tutorials
    Replies: 0
    Last Post: 15-10-09, 07:18
  3. Timer class of Actionscript 3.0
    By Flep in forum Tutorials
    Replies: 6
    Last Post: 21-02-09, 00:59
  4. Using PrintJob class of Actionscript 3.0
    By Flep in forum Tutorials
    Replies: 0
    Last Post: 19-11-08, 06:12
  5. CheckEmail Class - Actionscript 3.0
    By Flep in forum Tutorials
    Replies: 9
    Last Post: 19-12-07, 08:03

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

Search Engine Optimization by vBSEO