Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

Timer class of Actionscript 3.0

This is a discussion on Timer class of Actionscript 3.0 within the Tutorials forums, part of the Flash English category; Here we are checking out another new class of Actionscript 3.0 . The Timer class is an embellishment of the ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-10-07, 16:34
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Timer class of Actionscript 3.0

Here we are checking out another new class of Actionscript 3.0 .
The Timer class is an embellishment of the methods setInterval and setTimeout and, actually, Adobe suggest using these instead.
When you create an instance of the Timer class, it just executes a certain piece of code at regular intervals.
You can specify the frequency of the intervals and the number of times it needs to be repeated.
For example"
I create an FLA and save it as " prova_timer.fla " .
I create the Document Class, an AS file saved as " Prova.as " , structured like so:
Code:
package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;
	
	public class Prova extends MovieClip
	{
		private var numQuadrati:int=25;
		private var lato:int=25;
		private var distanza:int=10;
		
		private var andata:Boolean=true;
		
		private var clips_array:Array;
		private var points_array:Array;
		
		private var timer:Timer;
		
		public function Prova()
		{
			clips_array=new Array();
			points_array=new Array();
			
			disegnaQuadrati();
			posizionaQuadrati();
			initTimer();
		}
		
		private function disegnaQuadrati():void
		{
			for(var i:int=0;i < numQuadrati;i++)
			{
				var sprite:MovieClip=new MovieClip();
				sprite.graphics.beginFill(0x000000,1);
				sprite.graphics.moveTo(-lato,-lato);
				sprite.graphics.lineTo(lato,-lato);
				sprite.graphics.lineTo(lato,lato);
				sprite.graphics.lineTo(-lato,lato);
				sprite.graphics.lineTo(-lato,-lato);
				addChild(sprite);
				clips_array.push(sprite);
			}
		}
		
		private function posizionaQuadrati():void
		{
			var piccoloW:Number=Math.floor(this.parent.stage.stageWidth/5);
			var piccoloH:Number=Math.floor(this.parent.stage.stageHeight/5);
			for(var i:Number=0;i < 5 ;i++)
			{
				for(var j:Number=0;j < 5;j++)
				{
					var point:Point=new Point(piccoloW*j,piccoloH*i);
					points_array.push(point);
				}
			}
			for(var k:int=0;k < points_array.length;k++)
			{
				clips_array[k].x=lato*2+points_array[k].x;
				clips_array[k].y=lato*2+points_array[k].y;
			}
		}
		
		private function initTimer():void
		{
			timer=new Timer(100,clips_array.length);
			timer.addEventListener(TimerEvent.TIMER,this.gestioneIntervallo);
			timer.addEventListener(TimerEvent.TIMER_COMPLETE,finitoEffetto);
			timer.start();
		}
		private function gestioneIntervallo(t:TimerEvent):void
		{
			if(andata)
			{
				clips_array[timer.currentCount-1].width+=20;
				clips_array[timer.currentCount-1].height+=20;
			}
			else
			{
				clips_array[timer.currentCount-1].width-=20;
				clips_array[timer.currentCount-1].height-=20;
			}
		}
		
		private function finitoEffetto(TimerEvent):void
		{
			andata=!andata;
			initTimer();
		}
	}
}
And this is the result:







Later!
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !

Last edited by Flep; 13-12-08 at 06:18..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 13-12-08, 05:53
Junior Member
 
Join Date: Jan 2008
Posts: 24
Rep Power: 0
Pherankh is on a distinguished road
Re: Timer class of Actionscript 3.0

This code generates lots of errors - please check your code. The Flash demonstration playing on the page could not be using this same code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 13-12-08, 06:19
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Re: Timer class of Actionscript 3.0

Sorry, I did not added the BBcode tag of the forum correctly.
Try now.
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 13-12-08, 20:45
Junior Member
 
Join Date: Jan 2008
Posts: 24
Rep Power: 0
Pherankh is on a distinguished road
Re: Timer class of Actionscript 3.0

Thank you for taking the time to update this code. It will run as is, but, do not try to format the code in Flash or it will break!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 14-12-08, 09:57
Junior Member
 
Join Date: Dec 2008
Posts: 1
Rep Power: 0
dressup9 is on a distinguished road
Re: Timer class of Actionscript 3.0

thanks !
__________________
Dressup9.com - DressUp Games For Girls
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 20-12-08, 17:44
Junior Member
 
Join Date: Jul 2008
Posts: 1
Rep Power: 0
theyejin is on a distinguished road
Re: Timer class of Actionscript 3.0

good!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Slicing an image with the Matrix Class of Actionscript 3.0 Flep Tutorials 7 17-11-08 01:48
SWF to PNG with Actionscript 3.0 - ByteArray class Flep Tutorials 74 31-10-08 17:26
Actionscript calls Javascript - ExternalInterface class of Flash CS3 Flep Tutorials 1 21-10-08 16:30
Actionscript 3.0 e la classe Timer Flep Articoli e tutorials 7 27-07-08 14:22
CheckEmail Class - Actionscript 3.0 Flep Tutorials 9 19-12-07 08:03


All times are GMT. The time now is 16:45.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap