Pages: [1]
  Print  
Author Topic: Sharing embedded fonts from index.swf  (Read 1860 times)
phillyj8
Gaia User
**
Posts: 18


« on: November 14, 2008, 11:08:48 AM »

I'm sorry if this question has been answered elsewhere, but I've been scouring the forums for the last hour and couldn't find a definitive answer.

I'm trying to load a fonts.swf in index.swf and share it from there to the rest of my pages, without having to reload it in each one.  Currently, I have an identical function in each page that loads the same fonts.swf file over and over again.  Browser cache helps with this, but I'd obviously rather not have to rely on that.  I have included the swf in my site.xml, so it loads on the initial site load, but I'm not sure where to go from there - can someone guide me on what code to put in IndexPage.as as well as my other pages to share this swf without reloading?  Or is this not possible?

Here's my current site.xml, pretty simple:
Code:
<site title="Photo Gallery: %PAGE%" menu="true" indexFirst="true">
     <page id="index" src="index.swf">
    <asset id="galleryAssets" src="app/images/galleries.xml"/>
    <asset id="fonts" src="mkFonts.swf"/>
         <page id="nav" src="nav.swf" depth="top">
             <page id="home" title="Home" src="home.swf" menu="true" flow="preload" />
             <page id="gallery" title="Gallery" src="gallery.swf" menu="true" flow="preload"/>
             <page id="information" title="Information" src="information.swf" menu="true" flow="preload">
         </page>
     </page>
 </site>
Logged
liflaf
Gaia User
**
Posts: 70


« Reply #1 on: November 14, 2008, 11:21:10 AM »

Why not putting the shared fonts in the library of index.fla and import them into all other pages? Index will never unload.
But neither will an asset of index.swf, I guess. You shouldn't need to load your fonts.swf over and over again.
Logged
phillyj8
Gaia User
**
Posts: 18


« Reply #2 on: November 17, 2008, 10:48:47 AM »

Thank you, it wasn't working before, but now it does seem that that fonts.swf is available everywhere.  Not sure why it wasn't before - must've been an error in my code.
Logged
crokusdindus
Gaia Novice
*
Posts: 5


« Reply #3 on: January 09, 2009, 03:38:03 AM »

Hi guys,

I ve exactly the same question, because i'm new to gaia.
I read your answer but what do you mean by "import them into all other pages"? are you talking about the applicationDomain method?

Thanks  you

Charlie
Logged
liflaf
Gaia User
**
Posts: 70


« Reply #4 on: January 09, 2009, 05:19:04 AM »

I was talking about some old school method for sharing fonts (from the library).

Much better is the method described by Fis: http://www.gaiaflashframework.com/index.php/topic,445.msg5004.html#msg5004

AppDomain is not needed for fonts. You only need te make a swf with just your embedded font. Like so: http://troyworks.com/blog/2008/09/12/flash-runtime-font-sharing-embedding-with-only-partial-character-sets-how-to/

Next make this swf an asset of your index page and the font will be available throughout all your pages.

If you can't figure it out I will explain in more detail.
Logged
crokusdindus
Gaia Novice
*
Posts: 5


« Reply #5 on: January 12, 2009, 10:04:29 AM »

I've tried all day long to get those fonts embed....
If i add a font in the library of my index.swf , should  i acces to it from everywhere. simply by setting a textFormat like this:

tf.defaultTextFormat = new TextFormat("_font1",16,0);

where "_font1" is the as3 class linkage.

I can't find why it doesn't work, Can yo tell me more?
Logged
liflaf
Gaia User
**
Posts: 70


« Reply #6 on: January 12, 2009, 11:34:20 AM »

I don't see why you still would want to add the fonts to the library of index.swf. The link I sent you is clearly about making a separate font class.

This is more or less what worked for me:

Make a new .fla file (e.g. myarial.fla). Give the file a document class like MyArial.as. In this document class, put:

Code:
package
{
import flash.display.Sprite;
import flash.text.Font;

public class MyArial extends Sprite
{
[Embed(source = "arial.ttf", fontFamily = "MyArial", mimeType = "application/x-font-truetype")]
public static var _myArial:Class;

public function MyArial()
{
super();
Font.registerFont(_myArial:Class);

}
}
}


In this I example I've got the .fla file, .as file and the font (.ttf file) residing on the same location. You could also point to your fonts folder of your system, like: source="C:/WINDOWS/Fonts/arial.ttf"

Publish your .fla. You might get the warning that you have to install the Flex SDK to get this embedding to work. I belief I had to do this, don't remember why. Should be more about in the article.

Put your new font .swf (e.g. myarial.swf) in the deploy folder, and make it an asset of index.

Now, from anywhere in your project you should be able to use "MyArial" as you typeface.

Like:

Code:
var myTextFormat:TextFormat = new TextFormat;
myTextFormat.font = "MyArial";
myTextFormat.size = 24;
myTextFormat.color = 0x000000;

var myText:TextField = new TextField;
myText.embedFonts = true;
myText.text = "Just some text".
myText.rotation = 15; //this is to check if the font is actually embedded. If the text rotates, it is.

addChild(myText);


Logged
crokusdindus
Gaia Novice
*
Posts: 5


« Reply #7 on: January 13, 2009, 08:53:58 AM »

Thanks so much! it works
Logged
ookla
Gaia Novice
*
Posts: 8


« Reply #8 on: September 24, 2009, 02:03:41 PM »

My Workflow:

1) Embed all on "index", export like Steve teach here:

http://www.gaiaflashframework.com/wiki/index.php?title=Runtime_Font_Loading

2) Now tell xml to load your fonts.

Code:
 <page id="index" src="index.swf" fonts="Calibri,CalibriBold,CalibriItalic,Helvetica25">

3) Go to a simple page an put this code on some page:

Code:
trace("all fonts fonts: "+Gaia.api.getAvailableFonts()); // returns 'Helvetica25,CalibriItalic,CalibriBold,Calibri'

var txtFmt:TextFormat = new TextFormat();
txtFmt.font = Gaia.api.getFontName("CalibriBold");
txtFmt.color = 0xFFCC00;
txtFmt.size = 24;

var tf:TextField = new TextField();
tf.text = "Hello Yellow CalibriBold!";
tf.embedFonts = true;
tf.width = 400;
tf.x = 0;
tf.y = 30;
tf.rotation = 12; // if rotates, it's embeded

tf.setTextFormat(txtFmt);

addChild(tf);
         

4) Smile!

[]'s

ookla

Logged
Melvyn
Gaia Novice
*
Posts: 4


« Reply #9 on: September 25, 2009, 07:26:50 AM »

What I do also to use fonts in textfields created in Flash IDE "design mode" (not by code):

Export a fonts.swf file as described in "Runtime Font Loading" section, check "Export for runtime sharing" and specify "fonts.swf", or any path relative to your main.swf file (on this example I have a swf/ folder for all my swf files except main.swf).


In your pages FLA's, create the fonts in the library with the same info but this time check "Import for runtime sharing" and type the same path specified at export.


Now you'll be able to use fonts in the IDE but those won't be compiled, they will be loaded instead from fonts.swf.
Make sure you select the fonts at the top of your list with a star after font name.


Put that fonts.swf as an asset in index page, and there you go! Now you can use your fonts in Design View as well as in Actionscript  Smiley
Logged
Pages: [1]
  Print  
 
Jump to:  

TinyPortal v1.0 beta 4 © Bloc