• Feedburner RSS
  • Comments RSS
  • Post RSS

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

Objects

var obj:object = new Object();
var obj:object = {};

Arrays

var arr:Array = new Array();
var arr:Array = [];

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<arrStuff.length; 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<numLen; 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.