|
Frequently asked questions
translator: Fazal Khan
Can I use libraries published for Flash player 6 with projects that have been made for Flash player 7?
Yes, probably.
The reason why it doesn't work now is because of the following: when loading an external movie from another version, the loaded movie uses object _global, which is what all other versions use. If it loads a different version, then you will have two object _global.
The script used for library self-initialization simply doesn't see object font_mng because font_mng is in another _global:
if (font_mng.registerTextFormat("body_i", this.body_i_txt)) {
this._parent.removeMovieClip();
}
The loaded library movie cannot find object font_mng in its version _global object - in fact there it is not present.
Other way of access to font_mng object is required: absolute reference to font_mng object creation and using this reference for library self-initialization.
In main movie:
#include "SFM.txt"
_level0.font_mng = font_mng
ASSetPropFlags(_level0, "font_mng", 7, 1);
In libraries:
this.font_mng = font_mng || _level0.font_mng;
if (this.font_mng.registerTextFormat("headerb", t_txt)) {
this._parent.removeMovieClip();
}
example sources
I was able to use my shared font without a problem until I added a static text field styled with the same font elsewhere in my application. My shared font stopped appearing everywhere, or appeared with many characters missing. When I take the static text field away, everything works normally. Why?
Steven Luscher:
Flash will favor the character set embedded in text fields in the authoring environment over those embedded with SFM. For your SFM fonts to work, you must ensure that no text field in your application is styled with the font in question. It is recommended to style your text fields with either _sans or _serif before applying your SFM font.
translator: Nox Noctis www.noregret.org
- I use it in a seemingly right way, but it doesn't work.
First, check this list of common errors:
- Player version of the main .swf file differ from the version of library .swf files;
- There are static or dynamic text fields in your project and they use the same font as the one loaded by SFM;
- Required symbols are not embedded into library .swf file.
translator: Nox Noctis www.noregret.org
- SFM works fine when testing offline, but it fails to load fonts on the web.
Check, whether paths to library files could have changed.
If that is the case, find where your swf tries to point to.
You can input url in the Linkage dialogue in the following ways:
RELATIVE ADDRESS
Example:
SFM/arial_n_lib.swf
In this case the library file (arial_n_lib.swf) will be requested from: [path to main file]/SFM/arial_n_lib.swf, whatever the location of the main file (arial_n.swf) is.
Say, main.swf is located at:
file:///C|/mySite/main.swf
And you have the following url in Linkage dialogue:
SFM/arial_n_lib.swf
This way the main file will try to find the library at:
file:///C|/mySite/SFM/arial_n_lib.swf
This will work the same way in the web.
Conclusion:
Addressing a library depends on the location of the file that accesses the library.
When you move a main file somewhere, you need to move library files also.
And what is more, you need to duplicate library files if your project include multiple files in different folders.
To avoid duplicating the library, you can use absolute addresses.
ABSOLUTE ADDRESS
When running offline:
file:///C|/SFM/arial_n_lib.swf
or
/C|/SFM/arial_n_lib.swf
Using from web:
http://www.sharedfonts.com/SFM/arial_n_lib.swf
or
/SFM/arial_n_lib.swf
This way the library address doesn't depend on the location of the file, that uses it. And that is far more convenient to know the exact full path of the library.
GENERAL RECOMMENDATIONS:
For offline tests of web projects:
Create a folder named "SFM" on drive "C" and place all your font libraries there, using absolute addresses as shown below:
file:///C|/SFM/arial_n_lib.swf
For web:
Create a folder named "SFM" in the root directory of your site and place all your font libraries there using relative addresses as shown below:
/SFM/arial_n_lib.swf
Check at run-time whether project is launched from the web or not, and change the library file path accordingly:
_root.sfm_prefix = this._url.substr(0, 4) == "file" ? "file:///C|/" : "";
_root.createEmptyMovieClip("tmp_mc", 0);
_root.tmp_mc.loadMovie(_root.sfm_prefix+"/SFM/arial_n.swf");
This way you will be able to move your project from offline to the web or vice versa without having to change anything in your main file.
For CD projects:
Using relative addresses is highly recommended, as you can not be shure which drive letter the CD drive has.
To avoid the head ache, all the swf files that use font libraries should be placed in one folder and all the library files should be placed in the other one. Relative paths should be used in the library files.
translator: Nox Noctis www.noregret.org
- I want to use embeded fonts for text fields. how do I do it right?
There are two techniques: use SFM or just embed the desired fonts into swf.
You can find the detailed manual for using SFM in the HELP section.
If you choose not to use SFM, I would recommend the following:
THE MAIN POINT: do not embed a font by placing it's symbol into library.
If you do, your capabilities of choosing the character range will be severely limited.
Recommendations:
1. Create text fields.
Create a dynamic text field for each font that you want to embed. Place them off the Stage in the frame that follows preloader. Having these text fields in one frame is enough to make fonts available for all the frames that follow. Note, that you must create a text field for each of font decoration styles that you want to use: for bold, italic, and italic-bold.
2. Set a font and input its name in the corresponding text field.
You should have something like that:

3. Choose names of text format objects that will represent each font (this is somewhat similar to CSS)
and set the corresponding text field names. I did that in the following way:
default_txt and default_black_txt.
4. Now it's time to actually embed the fonts. Select a text field,
press the Character... button in properties window. This will open the "Character options" window.
Select the desired character sets (hold CTRL for multiple selection), press OK.
Note, that the majority of the symbols that you may need are included in Latin extended group or other groups.
Say, you want to embed only «»© glyphs. If that is the case, you don't need to include some entire group, there is another posiibility.
Input these glyphs into text field (important!),
Open the Character options menu again and press Auto Fill button.
You should get something like that:
I highly recommend you to input the desired glyphs into text field before writing them to
"Include these characters:" box by pressing Auto Fill.
There is a simple reason for that: font can have these glyphs missing.
If you do not see a glyph after inserting it into text field, that will show you that the chosen font doesn't include such
symbol.
If you input the glyphs directly into "Include these characters:" string,
you will see the symbols there, but you will not have them in the compiled swf file, and will spend some time trying
to guess the reason.
5. Making the fonts accessible for scripting. For this purpose write the following in the frame where you have text fields (in the top layer):
_level0.fmt_container = _level0.text_formats_container || {}
ASSetPropFlags(_level0, "fmt_container", 7, 1);
_level0.fmt_container.default_fmt = this.default_txt.getNewTextFormat()
_level0.fmt_container.default_black_fmt = this.default_black_txt.getNewTextFormat() We acquire a refference to container object _level0.fmt_container (and we create it, if it doesn't exist yet).
This container will hold the refferences to TextFormat objects.
We did not place container refference in _global, but placed it in _level0. That is vital, because we may want to use shared font libraries or use this swf as the shared one. And this way we avoid problems with access to _global from different versions of swfs.
In case you don't know: if you try to load an swf file published for Flash Player 7 into another swf file published for Flash Player 6, you won't have access to _global object. Try this:
swf v.7:
_global.any_variable = "hello world!"
this.any_mc.loadMovie("movie_published_to_6_player.swf")
swf v.6:
trace(_global.any_variable)
- and the reason is: _global object is not the same for different swf versions!!!
6. Usage. If you apply default_fmt or default_black_fmt to text fields
as follows:
my_txt.setTextFormat(0, 1000, _level0.fmt_container.default_fmt)
my_txt.embedFonts = true
You will see, that the size, color (etc.) settings change according to the style of default_txt and
default_black_txt.
Sometimes that's great, but sometimes that's wrong.
If you need to assign only a font face, I recommend the following:
var def_fmt = new TextFormat()
var sample_fmt = _level0.fmt_container.default_fmt
def_fmt.font = sample_fmt.font
def_fmt.bold = sample_fmt.bold
def_fmt.italic = sample_fmt.italic
my_txt.setTextFormat(0, 1000, def_fmt)
my_txt.embedFonts = true
There is also another way. You could create a new TextFormat object and set its font name directly:
var def_fmt = new TextFormat()
def_fmt.font = "Artemius TT"
my_txt.setTextFormat(0, 1000, def_fmt)
my_txt.embedFonts = true
And surprisingly that will work. However, that's the bad idea.
If you need to change the font,
in the first case you will need nothing but to change a font in your font-containing text field.
In the second case you will need to look through the whole code of the project to find the font name.
That's not that difficult, if you are the author of the code. But if some other developer tries to work with your source codes, he will be truly upset.
And the second reason not to set the font name directly is:
you can just misspell the font name or specify it with the wrong decoration style.
7. Frequently we need to use the text from external source with HTML and CSS formatting.
Be sure to embed the fonts as described above, and you will need no additional actions to use embedded fonts in html text. All you will need is to set the following:
my_txt.embedFonts = true Flash Player will find the designated font on its own at runtime.
This applies to shared libraries also.
So, what we finally arrive to:
we do not use font names at all.
Only TextFormat objects, that are created from the font-containing text fields, are used.
Thus, we control fonts and the included character sets.
Changing fonts does not require digging through the code. When using HTML or CSS formatting, the player finds the required fonts on its own. At first glance you may consider this to be a rather complicated solution. But when you have a little practice with it, you will find it simple and soon you will wonder how you could do without it before.
|