PDA

View Full Version : find certain values in a array



werehunt
August 23rd, 2009, 10:10 AM
I want to push into someFonts ONLY fonts which start with certain letter(s) (if they are any)

possible?



var systemFonts:Array = new Array();
var someFonts:Array = new Array();

systemFonts = Font.enumerateFonts(true);
systemFonts.sortOn("fontName");

for (var i:int = 0; i < systemFonts.length; i++) {//this will push all
someFonts.push(systemFonts[i]);
}

senocular
August 23rd, 2009, 10:17 AM
As you loop through your fonts, you'll need to check systemFonts[i].fontName.charAt(0) and see if it is a character you allow it to start with (using a switch or map). If so, then do the push.

werehunt
August 23rd, 2009, 10:25 AM
can you make it so that i can enter one or more characters (for example: "Helv") to search?

thanks