Skip to content
Memmie Lenglet edited this page Mar 16, 2015 · 1 revision

Alternative solutions to use a font in Flash

System font

The simplest, more demanding. Allow device font (if font installed on user's device) to be used, but disallow graphical and transformation effets like blend modes, filters, rotation, scaling.

Pro :

  • Simplest and lightest

Con :

  • Work only with installed fonts on device
  • Some effects not work with flash.text.TextField, only if there are rasterized (BitmapData)

Embed a font

Primitive way, usefull when we need to embed a font with only for Latin1 text or just for few chars.

Advantages :

  • Simple only for few fonts

Disadvantages :

  • Add weight needed to be loaded, depends number of fonts, their complexity and number of embedded chars

  • Could have heavy for Unicode fonts

  • Embed a font in a SWF

External libraries

2 kind of external libraries exsiting: shared library and runtime shared library (loaded dynamically). Used to externalize an application part, like fonts, code, images, etc., reducing the main application binary weight.

Shared library

It's supported natively by Flash Player via the usage of SWF tag ImportAsset2. It's know where resources are located and try load it automatically. This functionality could be used in Flash Professional, at Share in property panel of library elements. The external SWF must contains the SWF tag ExportAssets defining importable elements.

Advantages :

  • Could be used in common for multiple projects

Disadvantages :

Dynamic shared library

Same way describe below, but made dynamically (with code), where the location is not predefined. Be able to determine location depending variables like localisation, player version, geolocalisation, etc.

  1. load the library container with loaderInstance.load(urlRequestInstance);
  2. once completly loaded, register font Font.registerFont(loaderInstance.contentLoaderInfo.applicationDomain.getDefinition("fontClassName") as Class);

Advantages :

  • Could be used in common for multiple projects

Disadvantages :

Signed SWF

Since FlashPlayer 9.0.115.0

SWF files could be signed (*.swz). It's enable crossdomain cache of FlashPlayer, speeding load of same libraries on multiple domains. Once the signed SWF loaded, this one is keept Ad vitam æternam on user device under a unique ID which allow access to other domains (but on all domains the same original must be present in case of).

var requestInstance:URLRequest = new URLRequest("repository location of SWZ file");
requestInstance.hash = "SHA-256 key";//Where located the file is, the hash permit to identify it and get back from cache directly or if it's not present, loaded from provided URL
urlLoaderInstance.load(requestInstance);//The load of SWZ work only with an URLLoader

[]//Once the file completly loaded

var loaderInstance:Loader = new Loader();
loaderInstance.load(urlLoaderInstance.data);//load bytes of the SWZ

Note: Adobe call signed SWF: RSL (Runtime Shared Library)

Note 2: It seem according comment in source of TagValues.java from Flex SDK that SWF Tag ImportAsset2 support also "SHA-1" hash for SWZ

Dynamic SWF generation

It could be used, server side for FontStream

Server side, it's possible to generate a SWF on the fly with a CGI (Flex for Apache, swfmill, etc.), contais one static textfield with needed font chars.

Client side, a simple HTTP call, allow load of it and display :

displayObjectContainerInstance.addChild(loaderInstance);//add the loader to the displaylist
loaderInstance.load(urlRequestInstance);//start loading

Advantages :

  • Simple to handle it, client side
  • Small quantity of data over network

Disadvantages :

  • Disk and CPU usage, convert format (TTF to SWF)
  • Limited usage to dynamic text field, can't handle cumulative resources (successive additions of previous load) ^1^
  • Complex server side setting up (could be impossible with specific configurations)
  • Need good practices to handle unused ressources client side (loaderInstance.unloadAndStop()) ^1^
  1. This disadvantage not exist if, for FontStream, this way is used server side

Clone this wiki locally