Fix Textfields JSFL
Today Seb was having some issues when dealing with embedded fonts – read his post. He came up with some ActionScript ways to get around it. Well another way would be to use JSFL. A couple of my team members at Fuel Industries wrote the following JSFL script. It goes through your library and searches out any dynamic textfields. Once it finds one it makes sure it’s on a whole pixel, turns the auto kern off, embeds “UpperCase, LowerCase, Numerals, Punctuation” characters, and makes it not selectable. But you could make it do pretty much anything you can through JSFL.
fl.outputPanel.clear(); scanLibrary(fl.getDocumentDOM().library); function getIsWholeInt(n) { var s = String(n); if(s.indexOf(".") != -1) { return false; } else { return true; } } function round(n) { var s = String(n); var a = s.split("."); var num = parseInt(a[0]); var dec = parseInt(a[1].substr(0, 1)); if(dec >= 5) { num++; } return num; } /** * Scans the supplied flash library for linked classes and makes sure the textfields are set up properly * @param library A flash library to scan. */ function scanLibrary(library) { var items = library.items; var item; var replaceCount = 0; for( var i = 0; i < items.length; i++ ) { item = items[i]; if (item.itemType == 'movie clip') { var timeline = item.timeline; var h = timeline.layerCount; library.selectItem(item); library.editItem(); while(h--) { var k = timeline.layers[h].frameCount; while(k--) { var j = timeline.layers[h].frames[k].elements.length; while(j--) { var elems = timeline.layers[h].frames[k].elements; var p = elems.length; while(p--) { if(elems[p].elementType == "text" && (elems[p].textType == "dynamic" || elems[p].textType == "input")) { //Change the Static Text Fields to Dynamic if(elems[p].textType == "static") { elems[p].textType = "dynamic"; } //Handle all Dynamic TextFields if(elems[p].textType == "dynamic") { //Remove the ability to be selectable elems[p].selectable = false; } //Handle all Dynamic or Input Textfields //Remove the auto kern attribute elems[p].setTextAttr('autoKern', false); //Embed fonts UpperCase, LowerCase, Numerals, Punctuation elems[p].embedRanges = "1|2|3|4"; //Pop onto whole pixel var matX = elems[p].matrix; var x = matX.tx; if(!getIsWholeInt(x)) { matX.tx = round(x); elems[p].matrix = matX; } var matY = elems[p].matrix; var y = matY.ty; if(!getIsWholeInt(y)) { matY.ty = round(y); elems[p].matrix = matY; } } } } } } } } }
