|
Table of Contents
FontManager is intended for organization the access to the shared library fonts and gives absolutely new possibilities.
FontManager lets not to embed font libraries in the movie, but to load them to scene using the loadMovie
comand and then to use them in both main movieclip and any other loaded movieclip.
External libraries present itself as a pairs of swf-files: library file and container file. Library file filename depends on container file filename and is formed as: [container_file_name]+[_lib]+[.swf]. For example, if
the container filename is , then library filename should be
Libary file should contain a movieclip with following Linkage settings: "export for runtime sharing " parameter must be checked and "URL" path should be given too.
The movieclip should contain one named textfield with embed fonts.
Look for creating shared libraries section and example files to learn more.
Hereinafter these external libraries can be loaded and can be registered for using in movieclip using the FontManager methods.
Usage of the libraries organized in this way is not the only one possibility. FontManager is just a connector between shared library and other movieclips of the project, including loaded movieclips.
Access to font can be implemented in the following directions:
- Main movie can load external swf file and use its shared font library;
- Loaded movieclip can use shared font library from another external loaded movieclip;
- Main movie can contain its own shared font library and can use these fonts in any movieclip loaded externally.
By default single object is created during initialization: fonts_mng. This is the global object and it is hidden by using the ASSetPropFlags.
If you need to view the contents of the fonts_mng object it is enough to create reference to this object:
_root.show_me = font_mng
and view the variables listing using Test Movie mode.
Using FontManager gives following new possibilities:
- using the same library files through the whole site lets to minimize the size of data loaded by user.
Once loaded library files will not be loaded again to user machine but will be taken from browser cache.
- loading fonts when it is needed to load.
During the HTML parsing it is possible to define what fonts are required and then load and use them.
- easier localization (international support).
There is a lot of time needed to change the textfields properties and to embed the new fonts during localization. By using the font manager you can set up library at once and then all movieclips appearing on stage will use appropriate fonts.
Distribute data files and library files with localized fonts by corresponding directories at first and then you can localize the movie "on the fly", just by pointing to needed localization directory.
- redesign simplification.
It is enought to replace embed font in shared font library to apply these changes to all movies where this library is used.
- separating engine(kernel), data and libraries.
Now it is possible to make separation full-fledged. you can create a smart clip, which will create the scene using the xml, loading only necessary elements.
It is possible to create a font library using
Font Library Creator Extension from
Carlos Rovira.
Note: FontManager is made primarily for using with flash Player 6 so all examples and tutorial files are preferable to be published as the 6 version swf.
However it is possible to use FontManager with Flash Player 7.
About using FontManager with 7 version movieclips
Step 1: Creating the library movieclip and including font
- Create new FLA file and name it depending on name and attributes of the font which will be stored in this file. File name should consist of following parts:
for example: ,
where means that font is used for general purposes, and means that font syle contained in the library is italic.
If you want to create library with the same font but with plain font style, then name it body_p_lib.fla respectively, and if any other your company's developer will create body_b_lib.fla or body_bi_lib.fla, then you certainly will expect that this libraries use the same font with bold and bold-italic styles.
Do not use font names for library filenames. If font will be replaced subsequently, then there's much of inconveniences will appear. If arial_lib.swf library contains Times New Roman font, then developers will be surprised by the result during localization for Ethiopia or Russia.
Hereinafter keep this strategies of libraries naming and this way will allow you to control the library without any troubles, and, moreover, this process will be comprehensible not only for you.
- Create a movieclip and name it with comprehensive name, it is recommended to use the library name, for example:
. Right-click this movieclip, select the Linkage...
and check the Export for runtime sharing property,
any other Linkage properties settings is not important.
Set the URL path to swf file.
Name of the swf file should be must corresponding to filename after the publishing, for example: (read below about setting the absolute path)
- Create text field inside this movieclip;
- Insert the text in the text field. It is better to include name of the library, font style and language version in this text, for example: ;
- Assign the respective font for text field;
- It is necessary to include font in clip: Properties, Character..., All characters (or any other needed set of characters);

- Name the text filed instance (necessary), for example: ;
It is possible but is not recommended to place
other text fields in this movieclip even though at this moment you sure that these two fonts will be used always together.
It is recommended to place only one movieclip with only one textfield inside it containing only one embed font in one library file.
Otherwise you'll receive an unneeded risk of loading extra data and using the libraries with troubles;
- Inside the movieclip create new layer above the layer containing the text field and place the script there:
if (font_mng.registerTextFormat("body_i", this.body_i_txt)) {
this._parent.removeMovieClip();
}
- Save the FLA file with the same name as and compile it.
Step 2: Creating the container movieclip
- Create new FLA file;
- Save it in the same folder with the same name but not include _lib suffix, for example:
- For Flash MX: Close and then "Open as a Library" FLA file with textfield;
- Drag the movieclip containing textfield from shared library onto the Stage of new movie;
- Publish the file.
Library files now are ready to use.
Step 3: Loading and testing the shared libraries
- Create new FLA file and save it in the same folder, for example, with name;
- Place the FontManager initialization script at any frame, it is advisable to place it at the start of movie;
Now you can load the font and apply it to any textfield.
For testing purposes you can use my script, place it at the first frame _root after the FontManager initialization code:
_root.createEmptyMovieClip("temp_mc", 0).loadMovie("body_i.swf");
_root.createTextField("test_txt", 1, 0, 0, 200, 200);
_root.test_txt.text = new Array(30).join("Hello world! ");
font_mng.addListener(_root.test_txt);
_root.test_txt.onRegister = function(success, name, mng) {
if (!success) {
return trace("registerError : "+name);
}
trace("name:\n\t"+name+"\nfont:\n\t"+mng[name].font);
this.setTextFormat(mng[name]);
this.wordWrap = this.embedFonts=true;
};
- now test it. text in textfield will appear.
Step 4: Testing and using on site
Plan the location of your libraries on the site accurately.
When use on site the optimal and best way is to use the absolute or site-root-relative paths.
Note: if you wan to test the demo version of FontManager, you can do this only one way by using a
WebSpeed Simulator.
Open the Setup dialog and set the Local Website parameter ast a path to the folder where your project's test files scructure is stored.
Then press the "Browse Web" button and enter the http://localhost/ in the browser's address bar.
So, firstly create a folders where the library files will be stored.
In example path to library files is set as a .
If you are intending to use other location, take this into account.
- In the root folder of the site create a Libs folder, with SharedFonts folder inside
- Open the body_i.fla file
- Open the library and set the URL parameter in the Linkage Properties dialog box as:
- Compile the file; You'll receive an error message:
Error opening URL "file:///Libs/SharedFonts/body_i_lib.swf"
ignore this message;
- Copy body_i_lib.swf and body_i.swf
files to SharedFonts folder (you must not make any additional changes in body_i_lib file, it remains such as we created earlier);
- Open TestBodyItalic.fla file created earlier and replace
.loadMovie("body_i.swf")
to
.loadMovie("/Libs/SharedFonts/body_i.swf")
- Publish the file (Ctrl+F12) to get a HTML file.
- Copy the file to any location within the site.
- Open the page. In a certain time, after loading fonts you'll see that contents of the text field has gained a new formatting.
Step 5: Using in Flash Player 7
To use FontManager with Flash Plyer 7:
- create 6 version swf file 6й, containing FontManager initialization script;
- place this file within site and load it if necessary;
or
- place the FontManager initialization script inside the shared movieclip and insert this movieclip in clips
there's a only one inconvenience when use with Plash Player 7: necessity of the waiting while
file will be loaded, but due to its size (about 1 kbyte) this inconvenience is minimal. Moreover, such usage practice is recommended with Flash Player 6 too.
No other functional differences.
I have done a lot of experiments while developing the FontManager.
First FontManager version was a component.
During these experiments FontManager methods count decreased from eight to one,
events count decreased from four to one, and there were also two properties,
which I succesfully refused too. More than 50 files were created for testing. So, basing on this experience I can give you some recommendations.
In future, you'll find your own best ways, but i advice you to take my recommendations into attention:
Strive not to include FontManager initialization script in project.
The best way is creation a swf file containing this script and using it as a loaded module.
Even better is to create shared movieclip containing FontManager initialization script and to insert this
shared movieclip to the projects where it is necessary.
This will allow you to change FontManager initialization script while moving to new domain with no headache.
Do not use names of the swf library files inside your movies. Your system will be much more flexible if you create an xml file with description of your libraries. For example:
<fontlibrary version="1.0" author="Ivan Dembicki" >
<style name="body" font="Artemius TT" lang="rus" >
<plain id="body_p" url="/fontLibrary/rus/body_p.swf" />
<bold id="body_b" url="/fontLibrary/rus/body_b.swf" />
<italic id="body_i" url="/fontLibrary/rus/body_i.swf" />
<italicbold id="body_bi" url="/fontLibrary/rus/body_bi.swf" />
</style>
<style name="header" font="ArtemiusBlack TT" lang="rus" >
<plain id="header_p" url="/fontLibrary/rus/header_p.swf" />
<bold id="header_b" url="/fontLibrary/rus/header_b.swf" />
<italic id="header_i" url="/fontLibrary/rus/header_i.swf" />
<italicbold id="header_bi" url="/fontLibrary/rus/header_bi.swf" />
</style>
</fontlibrary>
Pay an attention to correspondence between ID nodes and names of the styles. Using ID this way it is easy to get the URL of the library container file.
And in tis case localization, e.g., for Japan takes only a creation of "/fontLibrary/jp/" folder,
populating this folder with library files and replacing the paths in xml file.
Transition from local to internet version becomes easier too.
One more advantage is a possibility of the visual checking the correspondence between fonts and styles.
You may do your XML description as you prefer, of course. This is just an example.
Use libraries self-registering, such as in examples. After registering you can delete libraries with no doubt.
Use local paths to libraries for local tests, and use absolute paths for internet.
Do not create you own FontManager instances, although this is possible by using the following code:
my_font_mng = new font_mng.constructor()
i suppose that it is necessary to know about such possibility, but use it only in the last resort.
Actions
Availability
Usage
font_mng.registerTextFormat( instanceName, textField )
Parameters
instanceName - string, sets the name of TextFormat object
textField - pointer to the textfield contained within the shared movieclip, which it is required to get textFormat object from.
Returns
Boolean. returns false,
if textfield contains no embed fonts or there's no
instanceName of the TextFormat object.
Otherwise returns true.
Description
Method. Creates TextFormat object within FontManager.
Shared movieclip containing sample textfield can be removed on completion.
TextFormat object within FontManager can be created basing on sample of any text field which resides
in shared movieclip and has an embeded fonts.
Checking of that text field is found in shared movieclip is entrusted on developer.
Directly before exit from the initialization procedure FontManager broadcasts an event
onRegister with initialization parameter.
Example
- the case with the loaded library, when calling from the shared movieclip (self-registering):
if (font_mng.registerTextFormat("body_i", this.body_i_txt)) {
this._parent.removeMovieClip();
}
font_mng.registerTextFormat("body_i", this.body_i_txt)
- the case with the library placed on Scene:
font_mng.registerTextFormat("body_i", this.any_mc.shared_mc.body_i_txt)
Availability
Usage
listenerObject.onRegister = function (success, name, instance_mng, textField ) {
}
Parameters
success
- Boolean, returns false,
it there's no TextFormat object name was passed when calling registerTextFormat
or if there's no embeded font within sample text field.
Otherwise returns true.
name - string, the name of the created within FontManager TextFormat object.
instance_mng - pointer to FontManager instance which called the resistration;
textField - pointer to the format sample textfield.
Returns
Nothing
Description
Event. Fired directly before exiting from the procedure of registration the TextFormat object in the FontManager.
Since FontManager is a broadcaster, he also has all methods and properties of the broadcaster.
Example
_root.createTextField("test_txt", 1, 0, 0, 200, 200);
_root.test_txt.text = new Array(30).join("Hello world! ");
font_mng.addListener(_root.test_txt);
_root.test_txt.onRegister = function(success, name, mng) {
if (!success) {
return trace("registerError : "+name);
}
trace("name:\n\t"+name+"\nfont:\n\t"+mng[name].font);
this.setTextFormat(mng[name], this);
this.wordWrap = this.embedFonts=true;
};
|