


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 »
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); }
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.
Download the Source File Here: http://www.elipticdesigns.com/flash/ex/textRandomizer/TextRandomizer.zip
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"];
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";
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.