Flash Lite tip #0: Learn and use short code
This is something I've been meaning to start for some time. I spent a considerable amount of time combing the internets looking for tips when I got started. Honestly, its can be a tough platform and I felt like I was left in the dark when learning some of the more difficult things. So this is the start of a series that is meant only to help.
Flash Lite tip #0: Learn and use short code.
Well, I know there are many developers that might attack this for its ugliness, but it is a very easy way to save on file size, and ultimately on memory usage. What do I mean by short code?
I mean instead of writing out the Array, Object, or String functions, like this:
var myArray = new Array("item1", "item2", new Array("subItem1", "subItem2"));
You write the short hand version like this:
var myArray = ["item1", "item2", ["subItem1", "subItem2"]];
And you could get even smaller if you want to:
var i = "item";
var si = "subItem"
var myA = [i+1, 1+2, [si+1, si+2]];
The last example here is the least impact on memory and file size. Whether or not it runs faster, I'm not sure but I have seen files where large sets of data is stored in arrays and objects, and just by editing the syntax like this, I was able to cut out 10%-15% of the file size. When you are talking mobile, that is some serious savings. Keep in mind that your whole flash file has to be loading into the memory before it can be used so shrinking that file size will instantly give you some memory savings.
So here are the equivalents:
var obj = new Object();
var obj = {};
var str = new String();
var str = "";
var arr = new Array();
var arr = [];
Julie (not verified):
Thanks for the tips on short code. I'm not very good at coding yet, so I appreciate all the tips I can get!