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;
								}
 
							}
						}
 
					}
 
				}
			}
		}
    }
}
Continue reading » · Rating: · Written on: 08-24-09 · 4 Comments »

Guy Watson’s FileSystem Extension

Even though Flash now comes with the FLfile object, Guy Watson’s FileSystem extension still has a handful of features that FLfile doesn’t have. I went looking for the api and couldn’t find it on his site anymore so I wanted to put it up here. If you don’t have the extension you can download it here.

Here is the list of methods. For now you’ll have to guess what the parameters are, but I’ll try and fill those in as I go.

  • FileSystem.version()
  • FileSystem.browseForFolder()
  • FileSystem.getFileSize()
  • FileSystem.getFolderSize()
  • FileSystem.createFolder()
  • FileSystem.folderExists()
  • FileSystem.renameFile()
  • FileSystem.renameFolder()
  • FileSystem.copyFile()
  • FileSystem.copyFolder()
  • FileSystem.deleteFile()
  • FileSystem.deleteFolder()
  • FileSystem.getFolderContents()
  • FileSystem.saveTextFile()
  • FileSystem.readTextFile()
  • FileSystem.setCurrentFolder()
  • FileSystem.executeApplication()
  • FileSystem.executeDocument()
  • FileSystem.readRegistryRaw()
  • FileSystem.readRegistryString()
  • FileSystem.writeRegistryString()
  • FileSystem.readRegistryInteger()
  • FileSystem.writeRegistyInteger()
  • Continue reading » · Rating: · Written on: 07-25-07 · No Comments »

    Snippets Panel v0.1

    Yesterday I was going through the list of new features in CS3 for the JSAPI and I found fl.clipCopyString(string). This has been a feature I have been waiting for since mx2004 came out. And more just because I wanted to create a Snippets Panel. So I spent some time yesterday putting together something pretty quick. I haven’t tested it all that much and the UI is pretty simple right now. But I’d like to get some feedback first before going moving to far forward. The thing to keep in mind is that you can only copy the snippets to the clipboard and they don’t actually get pasted where your cursor has focus. But it still beats having to type out all those EventDispatcher mixins everytime.

    Let me know what you think.

    Snippets v 0.1 

    Continue reading » · Rating: · Written on: 05-30-07 · 5 Comments »

    Key Code Panel

    I always find myself creating really simple blank flash files that trace out key codes that I need. So I figured it should finally be a panel. All you have to do is give the panel focus and it will display the key code for the key that has been pressed.

    Key Code Panel Download

    Continue reading » · Rating: · Written on: 03-13-07 · 2 Comments »

    Library Items Panel Updated

    Thanks to

    Continue reading » · Rating: · Written on: 03-05-07 · No Comments »