Archive

Posts Tagged ‘Timer’

news review -> 9th week of 2009

March 3rd, 2009 Fabian No comments

here are some articles i was interested in this week…

> Jesse Warden dot Kizz-ohm » Parsing & Rendering Lots of Data in Flash Player

> AgileAgenda Basecamp Edition (Basecamp + Actionscript) at Marc’s Musings

> Flex 4 SDK downloads now include Spark skins for all the components « Flex Butterflies and Bugs

> SoTexty AS3 Text Effects Framework | sakri rosenstrom

> Nascom › Can Google index Flash?

> Find Flash, Flex and AIR Jobs on Twitter at Daniel Dura

> Create PDF in runtime with Actionscript 3 (AlivePDF, Zinc or AIR, Flex or Flash)
« flash platform! {desktop, mobile, touch screen…}

> flexandair.com » Don’t User the Timer to Make Timers

> FiTC Amsterdam | BIT-101 Blog

> Flash Coder » Grant Skinner’s gModeler UML tool for AS3

> aM laboratory – Karplus-Strong Guitar

> Marco Casario | RIAvolutionize the web: Auto-generation AIR tool to create ActionScript Value Objects and Data Access Objects (DAOs) for your ActionScript 3 applications

> AdobeTV: New Flex Builder “Gumbo” Features | Ryan Stewart

> OOP & Designs Pattern Principles: Ready for Work | ActionScript 3 Design Patterns

> Mr.doob’s blog | ActionScript Tween Libraries

> Niqui Merret » Choosing a video format and codec

> Comet & Actionscript: CLICKTAG ACTIONSCRIPT 3

> Flashgamer: Actionscript syntax highlighter

> What You Must Know About the New Safari 4 Beta – NETTUTS

> #tweetcoding « Pixelero

> Your Models Into Papervision The Other Way | Mikko Haapoja’s Blog

> APE – Actionscript Physics Engine for beginners | DES 84 – Blog of DES84 Website

> Flex Monkey Patches » Getting the version of the Flex SDK that was used to compile a SWC

> Build Papervision3D on Browser by Wonderfl | ClockMaker Demos

> diamondTearz » Unity 3D for Flash Developers Tutorial Series and Cheat Sheet

> Andre Michelle » FITC Amsterdam Source Codes

> Adobe Flash Player 10 critical Update for Flash CS4 Professional! at I2fly

> Adobe AIR HTML Control, Flash Content and Garbage Collection « Greg Wilson’s Ramblings

> Farata Systems » Flex framework Clear Toolkit goes open source

> Pursuit of Simplicity: Using InvokeEvent.reason in AIR 1.5.1

> onebyoneblog » FITC Amsterdam – Day 2 in a Nutshell

> FlashApe » swffit – The smart swf resizer

> Grant Skinner #tweetcoding Contest 140 lines of AS3 to Win at .swfgeek

> Embedding Fonts In Flex – Tip

> Monitoring System Volume changes with Adobe AIR at Mike Chambers

> Flex cookbook beta – Transitioning from Flash to Flex: An overview

> Characters Not Embedding With Flex DefineFont4

> John Nack on Adobe: “Everyday Timesavers” now on Adobe TV

> Getting Started with Alternativa 3D | The Tech Labs

> Creating cinematic effecs with Adobe Pixel Bender and JavaScript – Adobe AIR Team Blog

Categories: flash, flex, general, news review

pause Timer with ExtendedTimer in ActionScript 3.0

October 16th, 2008 Fabian 28 comments

hey guys, last week i needed to pause several timers and resume them later on. i ran into a problem which i try to explain in an little example.

so let’s say you start a Timer with 1000 milliseconds delay and stop it after 600 milliseconds. if you call Timer.start() again, it starts with a new delay of 1000 milliseconds again. there is no built-in possibility to resume the timer for the remaining 400 milliseconds. i thought “nothing easier than that, just call Timer.pause()”. but there was no such method, so i decided to write my own ExtendedTimer class and add the pause functionality. now i like to share it with you…

> ExtendedTimer.as
package com.fjakobs.utils
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	/**
	 * @author fjakobs
	 */
	public class ExtendedTimer extends Timer
	{
		private var _startTime : Number;
		private var _initialDelay : Number;
		private var _paused : Boolean = false;

		public function ExtendedTimer(delay : Number,
									  repeatCount : int = 0)
		{
			super(delay, repeatCount);
			_initialDelay = delay;
			addEventListener(TimerEvent.TIMER,
						    onTimer,false,0,true);
		}

		private function onTimer(event : TimerEvent) : void
		{
			_startTime = new Date().time;
			delay = _initialDelay;
		}

		override public function start() : void
		{
			if(currentCount < repeatCount)
			{
				_paused = false;
				_startTime = new Date().time;
				super.start();
			}
		}

		public function pause() : void
		{
			if(running)
			{
				_paused = true;
				stop();
				delay = delay - (new Date().time - _startTime);
			}
		}

		public function get paused() : Boolean
		{
			return _paused;
		}

		public function get initialDelay() : Number
		{
			return _initialDelay;
		}
	}
}