AARON SMITH’S CODE ENDEAVOR

New TextAttributes Class in Guttershark

I added this new class called TextAttributes. It simplifies setting the right properties on a text field for text formats, stylesheets, a few other things, and the model has helpers to simplify it even more.

Here’s a model xml file:

<?xml version="1.0" encoding="utf-8"?>
<model>
 
	<assets>
		<asset libraryName="fonts" source="fonts.swf" preload="true" />
	</assets>
 
	<fonts>
		<font libraryName="LucidaGrandeBold" />
		<font libraryName="LucidaGrandeRegular" />
	</fonts>
 
	<stylesheets>
		<stylesheet id="style1">
			<![CDATA[
			.body {
				color:#000000;
				font:LucidaGrandeBold;
			}
			.test {
				color:#ff0066;
			}
			]]>
		</stylesheet>
	</stylesheets>
 
	<textAttributes>
		<attribute id="attr1" styleSheetId='style1' wrapInBodySpan="true" antiAliasType="advanced" />
	</textAttributes>
 
</model>

Simple enough, the model defines fonts, stylesheets, and now the additional textAttributes can be defined.

Here’s a guttershark document controller showing the use of text attributes.

package 
{
	import gs.core.DocumentController;
	import gs.core.Preloader;
 
	import flash.events.Event;
	import flash.text.TextField;
 
	public class Main extends DocumentController
	{
 
		public var t1:TextField;
		public var t2:TextField;
 
		override protected function flashvarsForStandalone():Object
		{
			return {model:"model.xml"};
		}
 
		override protected function startPreload():void
		{
			preloader=new Preloader();
			preloader.addEventListener(Event.COMPLETE,onPreloadComplete);
			preloader.addItems(model.getAssetsForPreload());
			preloader.start();
		}
 
		override protected function onPreloadComplete(e:Event):void
		{
			super.onPreloadComplete(e);
			model.getTextAttributeById("attr1").apply(t1,t2);
                        t1.htmlText = "<span class='body'>hello <span class='test'>world</span></span>";
		}
	}
}

The Model has a new method called getTextAttributeById which will give you an instance of a TextAttributes class, which coincidentally contains a method to apply it to any number of text fields.

The TextAttributes class can be used by itself, but having a helper method on the Model just simplifies defining all that information in XML.

There’s another example in the guttershark repo.

  

No comments yet. Be the first.

Leave a reply