Forums: Flash:

 

AS2 - Dynamically loading fonts

first
 

DontBogartMe AS2 - Dynamically loading fonts

This is AS2 only, but feel free to let me know of how easily this can be done in AS3 if that's the case...

I have a Flash app that loads in lots of text from XML. This needs to be localized to Western Europe and also to Russian. At some point in the future it may go to Arabic or Chinese too.
So I need to embed the font that is used for the text.

How do you go about doing this?

I can't embed all fonts required in the main app FLA as that's too heavy.

I can't load a movie with the font embedded into a text field, because the font isn't then shared to the text fields in the main app that loads it.

And if I go the Import for runtime sharing route, I have to hardcode the path to the SWF that contains the font in the main app FLA - and that is causing me headaches, cos I don't want to have to duplicate the main app for each language version.


I've read of a technique where you imoprt not an FLA but a PHP file that then sends the right font file according to a session parameter - and if there isn't a better Flash-only way I may look into that, but I'm using ASP.NET not PHP and I don't really know where to go with that.


Thoughts please?

 

scudsucker

Ok.

If the app is on a website, you could do something like rewrite the url of the request for the font .swf to an appropriate .swf.

Eg, you hard code the path to the swf as /runtimesharing/fonts.swf, but you have you actual fonts.swf files in, eg

/runtimesharing/English/fonts.swf
/runtimesharing/Russian/fonts.swf,

Then in the global.asax, using a session var called "language",

(NB, pseudocode! I ripped this off a site I did 2 years ago and altered a few things),


void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext incoming = HttpContext.Current;
string oldpath = incoming.Request.Path.ToLower();
string newpath;
string language=( string ) Session[ "language" ];


// Regular expressions
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"/runtimesharing/fonts.swf", System.Text.RegularExpressions.RegexOptions.IgnoreCase | Sstem.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
System.Text.RegularExpressions.MatchCollection matches = regex.Matches(oldpath);

if (matches.Count > 0)
{
// redirect to the appropriate language
newpath= "/runtimesharing/"+ language + "/fonts.swf"
incoming.RewritePath(newpath);
}
else
{
// Display normal path if it doesn’t contain the regex string..
incoming.RewritePath(oldpath);
}
}

 

scudsucker

Probably dont need RegEx there, a simple string comparison would probably be just as good.

 

DontBogartMe

cheers for the .net tips there scuds - I was hoping for a Flash based answer though, and I'll hang on a bit 'til I give up on that one.

 
first
 

Forums: Flash: AS2 - Dynamically loading fonts

 
New Post
 
You must be logged in to post