Actionscript 3 Equalizer – Audio Visualizer

November 18th, 2010

An equalizer simply put is a visual representation of a song. This is something I always thought was a cool feature for the flash player, so I thought I’d create my own version.

Read the rest of this entry »

Actionscript 3 Custom Scrollbar

November 17th, 2010

Everyone always seems to be in need of a scrollbar class so I thought I’d take the time to make my own.

In case you don’t care to read anything and simply want the goods.
Download the Source Files Here: http://www.elipticdesigns.com/flash/ex/scrollbar/scrollbar.zip

The ultimate goal of a scrollbar is somehow calculate a percentage from 0% to 100% (or in Actionscript 3 a “Number” from 0.0 – 1.0). Once you create the percentage you can apply it to many things besides simply scrolling something. Many of the scrollbar classes I’ve seen on the internet are already “rigged” to something specific, this is where you’ll see mine is a little different. Instead of only scrolling content, scrollbars can be used for a variety of things as long as they run on percentages, and that is what mine will give you.
Read the rest of this entry »

Getters and Setters

November 13th, 2010

Getters and Setters are a very powerful tool in as3. A Getter is a function that “reads” or “returns” a value (usually a variable with your class), and a Setter is a function that “writes” or “changes” a value (usually the same variable). Basically you get the ability to define the read/write of a variable.
Read the rest of this entry »

AS3 Hashmap – Arraymap

December 21st, 2009

For a while I’ve been using classes I find online called “Hashmaps” which is basically a bunch of functions hooked up to a dictionary to manage keys/values. The only problem I have found is that when you try to retrieve all the items from your dictionary into an array, it won’t always been in the same order as you entered them. So I have created a class called “ArrayMap” which is Read the rest of this entry »

Actionscript Distance Between 2 Longitude Latitude Points

September 6th, 2009

Recently I’ve been doing alot of Google Maps stuff in flash, and have needed this more than once. This will give you the distance in miles or km between 2 Longitude and Latitude Points.

function getLatLngDistance($lat1:Number, $lng1:Number, $lat2:Number, $lng2:Number, $miles:Boolean=true):Number{
		var pi80:Number = Math.PI/180;
		$lat1 *= pi80;
	      	$lng1 *= pi80;
	      	$lat2 *= pi80;
	      	$lng2 *= pi80;

	      	var earthRadius:Number = 6372.797; // mean radius of Earth in km
	      	var dlat:Number = $lat2-$lat1;
	      	var dlng:Number = $lng2-$lng1;
	      	var a:Number = Math.sin(dlat / 2) * Math.sin(dlat / 2) + Math.cos($lat1) * Math.cos($lat2) * Math.sin(dlng / 2) * Math.sin(dlng / 2);
	      	var c:Number = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
	      	var km:Number = earthRadius*c;
     	 	return ($miles ? (km * 0.621371192) : km);
}

Multiple Textfield Text Randomizer

August 2nd, 2009

So you’ve probably seen these before, but this is my own version. This is one of those text effects you see where the textfields reveals with random letters.

Get Adobe Flash player

Download the Source File Here: http://www.elipticdesigns.com/flash/ex/textRandomizer/TextRandomizer.zip

Multiple ways to declare variables

April 17th, 2009

When declaring variables like objects or arrays, there is more than 1 way to declare them. I’m not exactly sure which way is faster, but I have used both scenarios in a variety of occasions. I’m putting this here just to help clarify they mean the same thing.

//Object Declaration 1
var objData:Object = new Object();
objData.fname = "Mr.";
objData.lname = "Krinkle";

//Object Declaration 2
var objData:Object = {fname:"Mr.", lname:"Krinkle"};

//Arrays Declaration 1
var arrData:Array = new Array();
arrData.push("Mr.");
arrData.push("Krinkle");

//Arrays Declaration 2
var arrData:Array = ["Mr.","Krinkle"];

Actionscript naming Conventions

April 17th, 2009

Everyone seems to know the feeling of being lost knee deep in a mess of code.

By using naming conventions you can help reduce the clutter….or at least organize your variables.

Here are some improvements that may help to keep your sanity.

1st Line: wrong way
2nd Line: right way

Numbers: use “num”

var thing:Number = 1;
var numThing:Number = 1;

Strings: use “str”

var thing:String = "hello";
var strThing:String = "hello";

Read the rest of this entry »

Optimizing a For loop

April 17th, 2009

Alot of the time I spend developing flash, I’m always looking for ways to optimize my code and make it run faster. Take for instance the following code.

var arrStuff:Array = new Array();
arrStuff.push({label:"thing1"});
arrStuff.push({label:"thing2"});

for(var i:int=0; i

Should be written like so

var arrStuff:Array = new Array();
arrStuff.push({label:"thing1"});
arrStuff.push({label:"thing2"});
var numLen:int = arrStuff.length;
for(var i:int=0; i

The reasoning for this is because it's less work for flash to do. Instead of every single loop looking up the array's length, it simply just compares it to a number (or int). It may not seem like much a difference, but later if your looping through thousands of objects it could definitely help.