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 7 of 7

Thread: Timer class of Actionscript 3.0

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

    Timer class of Actionscript 3.0

    flash templates
    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!

  2. #2
    Junior Member Settled In Pherankh is on a distinguished road
    Join Date
    Jan 2008
    Posts
    24
    Rep Power
    0

    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.

  3. #3
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    Re: Timer class of Actionscript 3.0

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

  4. #4
    Junior Member Settled In Pherankh is on a distinguished road
    Join Date
    Jan 2008
    Posts
    24
    Rep Power
    0

    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!

  5. #5
    Junior Member Settled In dressup9 is on a distinguished road
    Join Date
    Dec 2008
    Posts
    1
    Rep Power
    0

    Re: Timer class of Actionscript 3.0

    thanks !
    Dressup9.com - DressUp Games For Girls

  6. #6
    Junior Member Settled In theyejin is on a distinguished road
    Join Date
    Jul 2008
    Posts
    3
    Rep Power
    0

    Re: Timer class of Actionscript 3.0

    good!

  7. #7
    Junior Member Settled In lazarusomega2000 is on a distinguished road
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

    Re: Timer class of Actionscript 3.0

    I like the graphic but would you mind dumbing this down a little bit so I can figure out the code? I am trying to make a frame/graphic flash on and off at a certain frequency that will adjust over time (whether the frames change or not) and this sounds like what I need to use as a method. I just want to flash a background graphic on and off. Do you think you could post some code that does that with some notes on what I need to change in it to make the frequencies change?

+ Reply to Thread

Similar Threads

  1. Replies: 78
    Last Post: 01-04-10, 16:58
  2. Date class of Actionscript 3.0
    By Flep in forum Tutorials
    Replies: 0
    Last Post: 15-10-09, 06:19
  3. Using PrintJob class of Actionscript 3.0
    By Flep in forum Tutorials
    Replies: 0
    Last Post: 19-11-08, 05:12
  4. Actionscript 3.0 e la classe Timer
    By Flep in forum Articoli e tutorials
    Replies: 7
    Last Post: 27-07-08, 13:22
  5. CheckEmail Class - Actionscript 3.0
    By Flep in forum Tutorials
    Replies: 9
    Last Post: 19-12-07, 07: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