Pages: 1 [2]
  Print  
Author Topic: Thread for shared assets discussion  (Read 2061 times)
liflaf
Gaia User
**
Posts: 70


« Reply #15 on: December 27, 2008, 03:09:17 AM »

Somewhere above Fis wrote that font sharing is easier than he thought. But it is certainly not easier than I thought. I'm confused.

I've made my font.swf an asset of index.swf.

Code:
<page id="index">
<asset id="fonts" src="fonts.swf" depth="nested" />

Should I add appDomain="current" in it's attributes? Or is this only necessary for other types of shared assets, not for fonts?

Next, how should I reference the font class from font.swf? After reading articles on applicationDomain (like http://www.scottgmorgan.com/blog/index.php/2007/06/18/runtime-font-embedding-in-as3-there-is-no-need-to-embed-the-entire-fontset-anymore/), I tried something like this:

Code:
var FontLibrary:Class = Gaia.api.getPage("index").assets.fonts.applicationDomain.getDefinition("_Arial") as Class;
Font.registerFont(FontLibrary._Arial);

var tf:TextField = new TextField  ;
tf.defaultTextFormat = new TextFormat("_Arial",16,0);
tf.embedFonts = true;
tf.text = "This is a test to see if things are working as they should";
tf.rotation = 15;//if the text rotates fonts are actually embedded
addChild(tf);

Does this make any sense?

Logged
tore
Gaia User
**
Posts: 47


« Reply #16 on: December 27, 2008, 01:19:46 PM »

Funny, I figured this one out yesterday. I look all over the web for embedded font sharing solutions... no luck. Then I remembered how easy it was to communicate between swfs with Gaia, so I did some tests.

Here's what worked. I'm a Gaia novice so I don't know if this is best practice but...here's the solution.

In your NavPage.as, since it's always there, add a function like this.

Code:
public function shareEmbeddedTextField(where, str){
var fraf:MovieClip = new footerText();
var newFormat:TextFormat = new TextFormat();
newFormat.size = 25;

fraf.fText.selectable = false;
fraf.fText.wordWrap = false;
fraf.fText.autoSize = TextFieldAutoSize.LEFT;
fraf.fText.htmlText = str;
fraf.fText.setTextFormat(newFormat);
fraf.x = 210;
fraf.y = 55;
fraf.rotation = 45;
where.addChild(fraf);
}

new footerText(); is a linked MovieClip in the nav.fla Library. in the MovieClip there's a textField with my font embedded.
The two parameters of shareEmbeddedTextField() are "where" and "str" "where" is what swf to load the textfield into and "str" the string to fill the textField with.

In the page(swf) you want to use the shared font in add this code
Code:
var myString:String = "someText"
myField = Gaia.api.getPage("index/nav").content.shareEmbeddedTextField(this, myString);

That's it. Just to confirm I did the TextField.rotation and the font was there and rotated. Non embedded fonts wouldn't show when rotated.
The last line of the function uses "where" to palce the textField where ever you want. In this case I passed "this". Works like a charm. Obviously you could pass more params for font color etc.
Logged
jsus2maj7
Gaia Expert
****
Posts: 316

2725b7b1f6b


« Reply #17 on: December 27, 2008, 02:57:36 PM »

font sharing was easier than i thought because the fonts.swf didnt need to be in the same appdomain
in a bit of voodoo, Font.registerFont() makes the font globally accessible

appDomain="current" is NOT necessary for fonts

to access an embedded font i sift through the Font.embeddedFonts list and look for the one i want
if found i use it, if not i use default.

no need for the applicationDomain/getDefinition crap

also, the way i do this is much simpler than that article but i can't find a link to where i learned
i'll keep looking..

EDIT
found it
http://troyworks.com/blog/2008/09/12/flash-runtime-font-sharing-embedding-with-only-partial-character-sets-how-to/

this way is a bit hackish but is a lot less complicated than fighting with appdomain
« Last Edit: December 27, 2008, 03:01:18 PM by fis » Logged
liflaf
Gaia User
**
Posts: 70


« Reply #18 on: December 28, 2008, 01:28:15 AM »

Thank you Fis. Sounds like the perfect solution. I'm going to check it out.
Logged
jsus2maj7
Gaia Expert
****
Posts: 316

2725b7b1f6b


« Reply #19 on: December 30, 2008, 12:04:39 PM »

http://blog.ujungpandaran.com/2008/09/30/externalize-font-with-font-subset-font-weight-and-font-style-at-the-same-time/
Logged
raz-l
Gaia Novice
*
Posts: 3


« Reply #20 on: January 06, 2009, 04:28:58 AM »

this is great guys
this appDomain thing in general, and global font loading in particular should appear in the wiki...
http://www.gaiaflashframework.com/wiki/index.php?title=Assets
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

TinyPortal v1.0 beta 4 © Bloc