Flash Font Resizer v0.2

Making Flash text resize relative to the browser font size settings on the fly.

Comments and suggestions are very welcome. Email them to fransgaard@gmail.com, post them on my blog or post them on Accessify Forum.

And please let me know on fransgaard@gmail.com if you use the Flash Font Resizer for a project.


If this is the first time you read about the Flash Font Resizer I suggest you read the documentation on the first version.

 

What's different in version 0.2?

Version 0.2 is different from version 0.1 in that it uses two SWF files; One SWF to measure the px width of 1em as specified by the page's CSS, and one main SWF containing the actual Flash site.

The measurer SWF measures the px width of 1em and sends the value to the main SWF which will then use the value to resize the text.

The version 0.2 actionscript is also Flash 6 valid actionscript.

The measuring SWF

The measuring SWF's only purpose is to measure the width in pixels of 1em which is defined by the CSS of the page.

As it does not serve a visual pupose it is hidden with this CSS:

#ffr-measurer{
	position: absolute; 
	left: -0.9em; 
	top: 0; 
	width:1em;
	height: 1px; 
}

Note, ffr-measurer is not hidden completely as expected for the resons specified under known issues.

The actionscript follows same principle as before ie. when the the containing DIV is resized the actionscript measures the new stage width using pixels and specifies it as a value named "emInPx".

The only addition is LocalConnection function to send the pixel value found to the main SWF.

Stage.scaleMode = "noScale";
Stage.align = "tl";
var ffrMeasurer = new Object();
ffrMeasurer.onResize = function() {
	stretchIt();
};
function stretchIt() {	
	emInPx = Stage.width;	
	// Send font size value to FFR main
	var sending_lc:LocalConnection = new LocalConnection();
	sending_lc.send("lc_name", "methodToExecute", emInPx);
}

Stage.addListener(ffrMeasurer);
stretchIt();

The main SWF

The main SWF contains more code, but most of it is content code like specifying text, moving elements to show that the stage is 100% high and wide etc.

The only relevant code for making the text resizing work is the code receiving the font size pixel value from the measuring SWF:

/* --------------- Recieve font size value from FFR measurer  --------------- */
var receiving_lc:LocalConnection = new LocalConnection();
receiving_lc.methodToExecute = function(emInPx:Number) {
	// Set font size of text based on value from FFR Measurer
	var my_fmt:TextFormat = new TextFormat();
	my_fmt.size = emInPx;
	content_txt.setNewTextFormat(my_fmt);
	content_txt.text = content_txt.text;
	
	// Call stretchIt() to move textarea to the middle again
	stretchIt();
};

receiving_lc.connect("lc_name");

Creative Commons License

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.

No credit required, but please email fransgaard@gmail.com if you use the Flash Font Resizer for a project or modify it.


Comments and suggestions are very welcome. Email them to fransgaard@gmail.com, post them on my blog or post them on Accessify Forum.