Hello,
Right now if I create a Font object in Flash Professional and export it for actionscript, when I create a new instance of this font in actionscript, its fontName property is the original font that I had embedded.
For example, if the library symbol for the font's name is ApplicationFontRegular, and the class name exported in Flash Professional is also ApplicationFontRegular, its fontName property is still Century Gothic if the font I use is Century Gothic. This means that I must use the font name property Century Gothic in any css file I want to use.
But if I change what the embedded font is, I have to change all my css files too, so it uses the correct embedded font.
I want to know if there is any way to give an embedded font a unique fontName property which can be used in a css file regardless of what font was originally embedded.
The real problem is, if I load in a .swf at runtime that just contains my font assets and register the font at runtime, I'd like it to work with my css files regardless of what .swf file I actually load in, if multiple .swf files embed different fonts. So one file could have embedded Century Gothic, another embed Arial, but they both share a fontName such as ApplicationFont so that they both can use the same css files which use the font name property ApplicationFont. And it'd also be great if I could tell TextFields made in Flash Professional to use a font by this fontName too, so art assets made in Flash Professional also don't care about what original font had been embedded and registered at runtime.
Is there any way to do this? This would be extremely useful to me.
Thanks,
Erik
Thanks for your reply,
I don't use css files to load my assets.
My assets are embedded into .swf files compiled by Flash Professional. Right now I have a .swf file for my art assets, a .swf file containing fonts, and a .swf file for my main application. I also have several css files.
My main application loads the .swf assets using the Loader class. For the fonts, it gets the font classes from the .swf file and registers them on runtime, after the .swf is loaded. The .css files right now are embedded in the application.
I want to be able to change the path to the .swf file containing the fonts so different fonts can be loaded in, so I could have for example a main font an a header font, but the main font and header fonts can change depending on the swf loaded. But I want them all to still work with the same css stylesheets. I think this could be accomplished if the loaded fonts have a fontName property which I set myself when I embed the font, and which I can refer to in the stylesheet. But flash always embeds a font with the fontName property the same as the original font which was embedded, as far as I can tell.
To summerize succinctly: is there any way to change the fontName property of a font when you embed it so it isn't "Century Gothic" or "Arial" or "Times New Roman", but instead a unique name set by you, which can be used in a stylesheet?
And the follow up question after that is: if yes, is there any way to tell a TextField created on stage in Flash Professional to use this name as its font, so I do not have to go through the hassel of changing every text field in every art asset to have a specific embedded font in actionscript?
I`m a little confused, I admit. In your 1st Post you talk about your Problem with css files
This means that I must use the font name property Century Gothic in any css file I want to use.
But if I change what the embedded font is, I have to change all my css files too, so it uses the correct embedded font.
I want to know if there is any way to give an embedded font a unique fontName property which can be used in a css file regardless of what font was originally embedded.
Then in your next post you state:
The .css files right now are embedded in the application.
In which application? The Flash application? Are you using a cms? Other webtechnologies like php? MySQL?
How Are they embedded (included like in a php file, plain text?)
Don`t get me wrong, I have a vague idea how to actually help you, but at this moment your problem is not really clear to me.
After some research I have an idea what you are hinting at: You are using this class to parse css files that you use inside your flash file to style Textfields applicationwide. And you want the font-family property to have a generic name that can be linked to different font assets? Is that correct?
The flash.utils class could be helpful.
if you load an Arial.swf that contains an exported Arial Characterset with Linkage "GenericFontName".
you would set up your Textfields like:
var embeddedFont:Font = new GenericFontName();
var textFormat:TextFormat = new TextFormat();
textFormat.font = embeddedFont.fontName;
var textField:TextField= newTextField();
textField.setStyle("textFormat", textFormat);
textField.setStyle("embedFonts",true);
textField.text = "The quick brown fox jumps over the lazy dog.";
trace("getQualifiedClassName(embeddedFont)"+getQualifiedClassName(embe ddedFont));
//result is "GenericFontName"
Thanks,
Yes, css files are embedded in the application. It is a flash application. They are embedded using the [Embed] metatag.
moccamaximum wrote:
After some research I have an idea what you are hinting at: You are using this class to parse css files that you use inside your flash file to style Textfields applicationwide. And you want the font-family property to have a generic name that can be linked to different font assets? Is that correct?
Yes, that is essentially right, if I understand you.
However your solution doesn't work for me. I cannot refer to GenericFontName() in any way inside the stylesheet that I know of, without in some way modifying the stylesheet at runtime. If you trace embeddedFont.fontName, it will just output "Arial". In other words, you need to specify Arial, not GenericFontName, as the font inside the stylesheet.
If you load in another .swf file with the Times New Roman characterset with linkage "GenericFontName", then you must change your .css files and tell them to use "Times New Roman" font instead of "Arial" to use the embedded font. This is the problem I've been referring to.
I already know how to tell a TextField to use the font from GenericFontName class inside actionscript. I want to know how to do it just using css and just using TextFields created in symbols in the Flash Professional library, and if this is possible, so that: a) for TextFields created in a library symbol I do not need to modify them at runtime and b) my style data is easily storable and editable entirely inside a css stylesheet without needing to specifically tell the TextField what font to use in actionscript.
I am sorry if this doesn't make any sense... I am not sure of a better way to explain it. My question isn't about how css files , or StyleSheet objects, or how to change the TextFormat of a TextField at runtime to use my embedded font. It is about how to emebed fonts with a fontName specified by me. The reason is because I think this is the most convenient solution to being able to swap fonts in and out with other fonts. But, I suspect this isn't possible.
You did give me an idea though, which is that I could make a util function to physically change the text of the StyleSheet to replace a string like "ApplicationFont" with whatever GenericFontName.fontName is, so the css will be created and edited to use generic names which are modified to what they need to be at runtime.
This won't help me use these generic fonts in a TextField added to a library symbol, however, which was actually the main thing I was after because I don't want to need to modify every single TextField inside a library symbol.
The Problem with Font is essentially that you have no setters. This was intended by Adobe, I don`t know why. Maybe legal restrictions.
From the original comments:
/**
* The Font class is used to manage embedded fonts in SWF files. Embedded fonts
* are represented as a subclass of the Font class. The Font class is currently useful only to
* find out information about embedded fonts; you cannot alter a font by
* using this class.
*
* You cannot use the Font class to load external fonts, or to create an instance
* of a Font object by itself. Use the Font class as an abstract base class.
* @langversion 3.0
* @playerversion Flash 9
* @playerversion Lite 4
*/
Now all you have to do is to make you a new dynamic property, that you can set yourself:
//SpecialFont.as
package
{
import flash.text.Font;
public class SpecialFont extends Font
{
private var alias:String;
public function SpecialFont()
{
// constructor code
}
public function setAlias(_alias:String):void
{
this.alias = _alias;
}
public function getAlias():String
{
return alias;
}
}
}
//Link the class to your compiler or simply put in a directory with your other class files
Then in you main.fla use sth. like:
var embeddedFont:SpecialFont = new GenericFontName();
embeddedFont.setAlias("Superfont");
trace("embeddedFont.fontName:"+embeddedFont.fontName);
//will trace the original fontname
trace("embeddedFont.getAlias():"+embeddedFont.getAlias());
//will get the Alias you set earlier
//you have now a dynamic property you can set yourself
important: you have now to change every base class in your LibraryFontassets from flash.text.font to SpecialFont
I don't think that will work, because the CSS code doesn't care about your getAlias() function.
However, you might be on to something, because a read-only property just about has to be a getter under the hood. If Adobe hasn't marked it final, you should be able to do something like
override public function get fontName():String {
return _alias;
}
If it is final, possibly you could approach it from the StyleSheet side and override the parsing method to look at some custom property.
Hello,
Thank you for all the useful replies. I actually considered Amy's solution, override get fontName, but I didn't think it will work, because I didn't think that TextFields actually have any reference whatsoever to the Font object. So, even if in Flash Professional I set a TextField to use a SpecialFont as its font family, internally it will just store a fontName, not the font itself. It matches the fontName against registered fonts to get the font. But, then again, maybe I didn't think that through enough, because it'd make sense for it to get that fontName property from SpecialFont (when the .swf is compiled from the .fla file) and all will be good. I say make sense, because somehow I doubt it is actually implemented that way
But maybe!
I'll see how it works.
Thanks. At least this conversation gave me ideas for several alternative solutions which I am pretty sure would work, but are less ideal.
Okay, the solution to this problem is to use the Embed tag rather than the library to create the font assets. The Embed tag allows you to set the fontName of an embedded font. For example, place this in frame 1 of the font .swf file:
[Embed(systemFont="Century Gothic",
fontName = "ApplicationFont",
mimeType = "application/x-font",
fontWeight = "normal",
fontStyle = "normal",
advancedAntiAliasing = "true",
embedAsCFF = "false")]
const REGULAR:Class;
[Embed(systemFont="Century Gothic",
fontName = "ApplicationFont",
mimeType = "application/x-font",
fontWeight = "bold",
fontStyle = "normal",
advancedAntiAliasing = "true",
embedAsCFF = "false")]
const BOLD:Class;
and then when the .swf is loaded by the Loader class, register the fonts:
var clip:MovieClip = this.content as MovieClip;
Font.registerFont(clip.REGULAR);
Font.registerFont(clip.BOLD);
And there you go, the font will have the fontName "ApplicationFont", and using "ApplicationFont" as the font in css will use the embedded font.
I am still not sure how to tell library assets containing TextFields to use this font, short of adding actionscript in the symbol or changing the font of the TextField when the asset is instantiated (both of which I really want to avoid). Adobe still refuses to allow you to specify a css file to apply to a TextField inside their authoring environment for some unfathomable reason...
Thanks
This thread has some interesting workarounds
Well, fortunately I made a Wrapper class which wraps display assets which actual functional objects by setting the asset to a _view property and adding it as a child of the Wrapper. I suppose I'll just change my protected setView method so it iterates through all children of the view asset and sets a stylesheet for any TextField found.
Thanks
North America
Europe, Middle East and Africa
Asia Pacific