« Gems from the Cave of Undocumented Features | Main | Getting a list of installed recordable fonts »

January 28, 2005

Getting a list of installed fonts

If you want to get a list of fonts that are installed on a computer at run-time using Lingo or JavaScript syntax, then you simply need to make use of the fontList() method for font cast members in Macromedia Director. It's really rather simple, here are the steps needed, including code examples.


1. Create a font cast member
You can do this ahead of time by inserting a font using Insert>Media Element>Font..., or you can do it at run-time using code:

-- in Lingo
tFontMem = new(#font)
-- or
tFontMem = _movie.newMember(#font)

// in JavaScript syntax
var tFontMem = _movie.newMember( symbol("font") );


2. Call the fontList() method off a font member reference
Once you have a reference to a valid font cast member you simply call the fontList() method off that reference:

-- in Lingo
tFontList = tFontMem.fontList()

// in JavaScript syntax
var tFontList = tFontMem.fontList();

When called this method builds a Lingo linear list of strings, where each string in that list is the name of a system-installed font. It's important to note that you're getting a list of _all_ installed fonts that can be used in your text and field cast members.


Stay tuned, next week I'll post about a variation on this theme that lets you get a list of the fonts that are insertable or "recordable" as font cast members as opposed to a list of each and every font that's installed.


Enjoy.


Disclaimer: I make no guarantees regarding validity or usefullness of the information contained in this post. This feature was left as undocumented, and therefore unsupported on purpose, it either wasn't fully developed and/or it wasn't fully tested. I suggest that you utilize this technique in experimental movies due to the potential risks involved. There is no guarantee that this undocumented feature will survive from release to release. Use this technique at your own risk!

Posted by thiggins at January 28, 2005 02:30 PM