Re: [Flashcoders] Downloading a .swc library

2010-09-23 Thread Glen Pike

 Hi.

I would think about using the [Embed] directive in pure AS3 code to 
create font swf files.  You can have one or more fonts in a swf which 
does not matter and you can load them in a runtime dynamically.


Here is an example of a Font file - you can setup a project in 
FlashDevelop that will compile this as the main class in a SWF file.  
For multiple Fonts, just duplicate the [Embed] line and the static 
variable for it (with a different name.


Using an FLA - it does not embed the font ranges in the same way.  I 
found there were only a certain range of characters in the IDE created 
SWF even when I changed the range to be embedded - only by de-compiling 
the SWF and looking at the glyphs embedded with Sothink's tool!


If you need unicode ranges, this page is really useful:
http://www.zenoplex.jp/tools/unicoderange_generator.html

Also lots of links I have used to piece together my methods:
http://blog.arwidthornstrom.com/2009/04/embedded-fonts-that-work-with-flash-ide-and-flex-sdk/
http://troyworks.com/blog/2008/09/12/flash-runtime-font-sharing-embedding-with-only-partial-character-sets-how-to/
http://www.betriebsraum.de/blog/2007/06/22/runtime-font-loading-with-as3-flash-cs3-not-flex/
http://developer.yahoo.com/flash/articles/runtime-fonts-as3.html
http://www.ultrashock.com/forums/actionscript/font-embedding-using-flash-as3-and-flex-3-a-109509.html
http://www.aaronwest.net/blog/index.cfm/2009/3/16/Lee-Brimelow-on-Creating-Runtime-Loaded-Fonts-in-Flash-CS4
http://mx.coldstorageonline.com/index.php?bid=48



The font is shown below - this is added to my config file - my 
application automatically loads any ".swf" files at startup (it is 
local, not net as a 7MB font with Traditional Chinese will strain your 
connection).  If I change languages, my XML file may specify a font to 
find -


IMPORTANT - the "fontName" in the XML matches the fontName in the Embed 
statement!


My Application "Screens" all use a public static variable called 
_defaultFont, which can be changed at runtime by the following function 
and all my components can access the defaultFont variable should they 
wish to use it (a snippet of XML is shown at the bottom).


Hope this helps - you can follow the links and work it out yourself if 
you want, or peek below:



Glen

protected function _findLanguageFont():void {
var langXML:XML = languages.language.(attribute("lang") == 
languageCode)[0];
debug(this, "will check for languageCode " + languageCode + 
" in " + languages.language.toXMLString());

_defaultFont = null;
if (langXML) {
if(0 != langXML.attribute("fontName").length()) {
debug(this, "Language has font " + langx...@fontname);
var fonts:Array = Font.enumerateFonts(false);
for(var i:int = 0;i < fonts.length;i++) {
var fnt:Font = fonts[i];
if (fnt.fontName == langx...@fontname) {
_defaultFont = fnt;
debug(this, "Language set _defaultFont to " 
+ defaultFont.fontName);

break;
}
}
}
}
}



package {
import flash.display.Sprite
import flash.text.Font;
/**
 * Times font embedding class example.
 * Whatever you set the "fontName" property to is what you use as 
the fontName property in the config file for the app.

 *
 * This is different to embedding fonts with Flash because you can:
 *
 * 1.  Set the unicodeRange - specify certain characters / ranges 
to embed, reducing file size.

 * 2.  Choose your own fontName to avoid "font clashes" at runtime.
 * 3.  Register the font in the file - the contstructor is called 
as the swf is loaded because this class is the
 * document class, so all you need to do is look for your font by 
fontName in your app.

 *
 * NB - Adobe's UnicodeTable.xml file was used to get the ranges 
for unicode, which omit the ? and a few other chars, so
 * this was doctored to include those (basically 
U+0300-U+030A,U+0041-U+005A was combined into U+0030-U+005A.

 *
 * @author Glen
 */
public class _Times extends Sprite {
//Basic Latin characters + some punctuation - don't use the 
Adobe UnicodeTable for Basic Latin - it misses  "?" = 0x030F
[Embed(source = "C:/WINDOWS/Fonts/TIMES.TTF", fontName = 
"_Times", fontFamily = "Times", mimeType = "application/x-font-truetype",
unicodeRange = 
'U+0020-U+002F,U+0030-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E')]

public static var _font:Class;

public function _Times():void {
trace("Font Loaded:: _Times");
Font.registerFont(_font);
}
}
}


Sample XML config file for the application - the asset called







symName="com.robothespian.screen.LanguagesScreen" startscreen="true" 
sho

Re: [Flashcoders] Downloading a .swc library

2010-09-23 Thread Kerry Thompson
Henrik Andersson wrote:

> SWC files are zip files with swf files inside them (and some other misc
> stuff). The flash player does not know how to deal with them.
>
> Or you could just load a swf like everyone else...

Fair enough.

Here's the issue with loading the .swf. It's all code and no assets.
I'm embedding fonts from external files on the fly. For example:

[Embed(
source='../fonts/Garamond3/GaramThrBolItaOsF.ttf',
fontName='Garam3BoldItalicEmbedded',
embedAsCFF='false'
)]
private static var Garam3BoldItalicEmbedded: Class;

If I had these embedded in a .fla, I could export them to AS and have
it working pretty quickly. The client wants an all-code Flex app,
though.

How do I access the fonts when they're not exported to AS? Make the
private static vars public? If so, how would I use the font?
textFormat.font = "className.fontName"; ?

Cordially,

Kerry Thompson
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Downloading a .swc library

2010-09-23 Thread Henrik Andersson
SWC files are zip files with swf files inside them (and some other misc 
stuff). The flash player does not know how to deal with them.


You would have to unpack the zip, read the metadata and feed the stored 
swf to Loader.loadBytes.


Or you could just load a swf like everyone else...

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] Downloading a .swc library

2010-09-23 Thread Kerry Thompson
I posted this to another list a couple hours ago, and didn't get any
takers, so I'll try here.

My client wants something a little different. His specs call for a
Flex program that, in code, embeds fonts from an external folder. He
then wants to download that and use the fonts in another .swf.

I'm thinking a .swc library is the way to go. I'm a little new to
using libraries that way, though. Can I create the font .swc in a
library project, and download it as I would a .swf or other asset?

I know that's not the way a library is usually used. I would usually
put the fonts in a .fla, export them to AS, and download the swf, but
the client would prefer it all be done in code, and not using Flash.

I have the file with the embedded fonts--all 16 of them. They
work--Ihave 16 text fields on screen, also created at run time, each
displaying text in the appropriate font. Can I just convert the
embedding part to a .swc, download it, register the fonts, and use
them? Would I use urlLoader?

Another possibility--is it possible to export the embedded fonts to
ActionScript, with code? I've done that plenty of times with embedded
assets, but not assets generated at runtime.

Cordially,

Kerry Thompson
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders