now, for a quick thing:
Be careful about how you have your loops placed when iterating through an array you remove items from!
Here's what I mean.
Say, for example, you have a list of files. You want to remove specific files from this list for whatever reason. The easiest way to accomplish this is to create another list of "blacklist" files to remove from the original list. This is where you need to be careful
Now, for an example direct from the Joe launcher.
the setup:
var blacklist:Vector.<String> = new Vector.<String>();
var dirLength:int = (File.applicationDirectory.nativePath + File.separator).length;
blacklist.push("META-INF" + File.separator + "signatures.xml");
blacklist.push("META-INF" + File.separator + "AIR" + File.separator + "application.xml");
blacklist.push("META-INF" + File.separator + "AIR" + File.separator + "hash");
blacklist.push("ConcernedLauncher.exe");
blacklist.push("ConcernedLauncher.swf");
blacklist.push("exceptions.txt");
blacklist.push("hashes.txt");
blacklist.push("launcher.propertes");
blacklist.push("launcherErrors.txt");
blacklist.push("launcherInfo.txt");
blacklist.push("mimetype");
loop one:
for (var i:uint = 0; i < blacklist.length; i++) {
for (var j:uint = 0; j < DirectoryScanner.files.length; j++) {
if (blacklist[i] == DirectoryScanner.files[j].substring(dirLength)) {
DirectoryScanner.files.splice(j, 1);
break;
}
}
}
loop two:
for (var i:uint = 0; i < DirectoryScanner.files.length; i++) {
for (var j:uint = 0; j < blacklist.length; j++) {
if (blacklist[j] == DirectoryScanner.files[i].substring(dirLength)) {
DirectoryScanner.files.splice(i, 1);
break;
}
}
}
both of those should work the same, correct? Nope! Here's why.
Loops don't really "restart" very well. Say the length of DirectoryScanner.files is 10.
If there's a match at i=5, then element #5 will be removed from the array, and element #6 becomes element #5. The loop then goes on to element #6, skipping the previous element #6 which is now element #5. This can result in random elements being skipped.
Loop #1 avoids this by having the array that gets elements removed from it as the inner loop, effectively "restarting" the search after each match.
There's much more effective and efficient ways of searching an array than going through each element, but this method is common enough to actually make a post on it :P