Archive | Custom Classes

Create A Flash Countdown Timer in AS3 Using A Class

Create A Flash Countdown Timer in AS3 Using A Class

Due to the popularity of one of my earlier posts, I’ve decided to extend the topic with a helpful Countdown Timer class. This handy utility provides a flexible and easy way to tie in countdown timer functionality into just about any design. It is designed to handle the grunt work of developing a Countdown Timer. It is not meant to replace the Countdown Timers available to the Flash community. It is purely meant to easily implement Countdown Timer functionality to you own custom design without reinventing the wheel.

Features Include:

  • Easily define a new Countdown Timer instance
  • Access to the countdown’s remaining days, hours, minutes and seconds
  • Easily update the target end date
  • Custom events that trigger upon Countdown updating and on complete

Getting started creating a fresh Countdown Timer

Implementing your new countdown timer design will require minimal ActionScript as the this utility will handle key events and updating of the remaining time.  All you need to implement this countdown functionality is a design and some time.  Enjoy!

Step 1: Importing the necessary classes

In order to use this utility within your Flash file, you would need to import the following two classes: CountdownTimer.as and CountdownEvent.as. Note: Make sure that the classes are local to your .fla file or if you are more comfortable modifying your ActionScript settings to accommodate the location of the classes, feel free doing so.

// Importing of the CountdownTimer Class
import com.flashspeaks.utils.CountdownTimer;
// Importing the CountdownEvent (used to update and notify upon countdown completion)
import com.flashspeaks.utils.CountdownEvent;

Step 2: Creating a new Countdown Timer Instance

Creating a new instance of the Countdown Timer is as easy as defining a new Countdown Timer instance and providing the target end date within the parameter. The values needed are the target year, month, and day. There are also optional hour and second values just in case you needed extreme flexibility in the target end date.

// This creates a new CountdownTimer instance and sets it target end date
var myCountdown:CountdownTimer = new CountdownTimer(year, month, day, hour(optional), second(optional));

Step 3: Retrieve the remaining days, hours, minutes, and seconds

In order to provide flexibility, I have provided public properties to obtain the days, hours, minutes, and seconds remaining separately allowing you to determine how you would like to display the remaining time. There is also a property called time that will return the remaining time as a whole number separated by colons. (00:00:00:00)

In order to retrieve the time, a new COUNTDOWN_UPDATE event listener needs to be established as it will be mapped to a function that will update upon every tick. It can be easily done like so.

myCountdown.addEventListener(CountdownEvent.COUNTDOWN_UPDATE, onCountdownUpdate, false, 0, true);

function onCountdownUpdate(e:CountdownEvent):void {
 // Update on screen visuals like text
}

Countdown has expired…what to do?

One of the requested key features was a way to easily determine when the countdown had expired. Some wanted to load a new timer, change on screen text to read 00:00:00:00 ,etc. Setting this up using CountdownTimer is fairly easy. To do so, you would essentially create a new COUNTDOWN_COMPLETE event listener and supplying what it is that you would like to occur within the event handler function. Check it out below!

countdown.addEventListener(CountdownEvent.COUNTDOWN_COMPLETE, onCountdownComplete, false, 0, true);
function onCountdownComplete(e:CountdownEvent):void {
 // Countdown finished...
 // HAPPY NEW YEAR
}

Change the target end date on the fly

Another huge request was to provide a solution to easily update the target end date via run-time. CountdownTimer provides a function called updateEndDate(new Date()) which allows you to simply provide a new target end date through its parameter. Your on screen visuals will automatically update to accommodate the new end date.

For example, let’s say you wanted to add a month to the target end date every time that it has expired you can to so by simply adding one month to current month within the onCountdownComplete event handler.

Complimentary Flash Countdown Timer design

What’s good Countdown Timer functionality without a good Countdown Timer design? Here’s a complimentary design that I will be providing with the download. It includes the example source and provides all of the source from this tutorial. Feel free to implement your own design! I’d love to see them!

Get Adobe Flash player

Download example files

Posted in Custom Classes, Flash Tutorials0 Comments

Mac OS X Mousewheel Support in AS3

Mac OS X Mousewheel Support in AS3

If you develop Flash on a Mac, then you probably already know the pitfalls of mouse-scrolling within your Flash projects on a Mac – it simply does not work.  The great thing about stuff not working is there is always someone out there looking to create a fix for it.

Gabriel created an AS3 solution to the mousewheel functionality on Mac OS X.  SWFMacMouseWheel integrates well with deconcept’s SWFObject and integrating this within your existing and future projects is rather painless.  Enjoy!

Additional Resources:

Posted in Custom Classes, Flash Tools0 Comments

As3Growl: Adobe AIR Learns To Growl

As3Growl: Adobe AIR Learns To Growl

Mike Chambers reports that the beloved open source Growl notification framework will be able to be leveraged by Adobe AIR applications.  If you are unfamiliar with Growl, Growl is a notification system for Mac OS X that allows applications that support Growl to send you notifications.

What is As3Growl?

As3Growl is the project behind this integration and provides an API for working with the new Growl functionality.  The project is hosted at Google code and already contains the complete API source, API docs, examples, documentation, unit tests and other information.

This is an exciting project and will only improve the user’s experience within Adobe AIR applications.  Thanks to Mike Chambers and all involved.

Additional Resources:

Posted in Custom Classes, Flash Tools, Industry News, Latest Adobe AIR News0 Comments

Create An Apple Style Preloader Using A Custon Class

Create An Apple Style Preloader Using A Custon Class

Steven sacks just posted custom class that creates an Apple style preloader.  It’s a simple class that uses the Flash Drawing API which makes it light and efficient. Check it out below.

package net.stevensacks.preloaders
{
	package net.stevensacks.preloaders
	{
		import flash.events.TimerEvent;
		import flash.display.Sprite;
		import flash.display.Shape;
		import flash.utils.Timer;

		public class CircleSlicePreloader extends Sprite
		{
			private var timer:Timer = new Timer(65);
			private static const SLICE_COUNT:int = 12;
			private static const RADIUS:int = 6;

			public function CircleSlicePreloader()
			{
				super();
				draw();
				timer.addEventListener(TimerEvent.TIMER, onTimer, false, 0, true);
				timer.start();
			}

			private function onTimer(event:TimerEvent):void
			{
				rotation = (rotation + (360 / SLICE_COUNT)) % 360;
			}

			private function draw():void
			{
				var i:int = SLICE_COUNT;
				var degrees:int = 360 / SLICE_COUNT;
				while (i--)
				{
					var slice:Shape = getSlice();
					slice.alpha = Math.max(0.2, 1 - (0.1 * i));
					var radianAngle:Number = (degrees * i) * Math.PI / 180;
					slice.rotation = -degrees * i;
					slice.x = Math.sin(radianAngle) * RADIUS;
					slice.y = Math.cos(radianAngle) * RADIUS;
					addChild(slice);
				}
			}

			private function getSlice():Shape
			{
				var slice:Shape = new Shape();
				slice.graphics.beginFill(0x666666);
				slice.graphics.drawRoundRect(-1, 0, 2, 6, 12, 12);
				slice.graphics.endFill();
				return slice;
			}
		}
	}
}

Additional Resources:

Posted in Custom Classes, Industry News, Latest Adobe Flash News, Latest Adobe Flex News0 Comments

InteractivePNG: Built to Fix a PNG Problem Within Flash

Don’t you hate when a transparent format like PNG isn’t so transparent to Flash. Finally, there is a way to ignore transparent parts of a PNG within MovieClips during mouse interactions. It is called InteractivePNG.

What is InteractivePNG?

InteractivePNG is a very handy little utility class that allows you to disable the hit area of a PNG if the pixels are transparent.

Currently, when you save out a PNG that has transparency, rolling over the transparent part of the PNG will still register as roll over because Flash still reads it as part of the image. However, with this class, that is no longer the case.

This may seem to be an easy trick or is it? Check out this class for yourself!

Other Resources Available:

Demo of InteractivePNG
Product Source
Documentation

Posted in Custom Classes, Flash Tools0 Comments

AS3cards: An ActionScript 3.0 Playing Card Engine

AS3cards: An ActionScript 3.0 Playing Card Engine

Recreate your favorite playing card game with this slick ActionScript 3.0 playing card engine called AS3cards. The AS3cards project provides a skinnable ActionScript 3.0 card engine for creating playing card games, with an example implementation of Klondike Solitaire. Everything needed can be found at Google Code.

Source: Google Code
Creator: Darron Schall
Demo: Klondike

Posted in Custom Classes, Flash Tools2 Comments

Page 1 of 11