Loading external classes in precompiled swf

Last year -march april 2010- meanwhile I was developing www.pipoideas.com (site at which I work together with Jorge Peraza) because of the 3D enviroment and because some incompatibilities, some textfield did not work well with embed fonts; my fastest idea was to find code or library to load a .ttf or .otf and be able to apply that font to a TextField. It didn’t work.

I had to read a lot to find that the closest solution was to embed the font inside a swf and load that swf, then extract the class, and then apply that class to the TextField.

At the end of this research I created two small but effective classes: “ExternalClass” and “ExternalFont”.

Using ExternalClass is easier than ExternalFont, so I decided to split them by its behaviour, this because ExternalFont lets apply directly to the TextField the required font.

With ExternalClass if you already have an swf with a class inside it, you can load it, and then call it:

import net.absulit.arbolnegro.data.ExternalClass;

var _externalClass: ExternalClass;
_externalClass = new ExternalClass();
_externalClass.path = "MyPrecompiledClass.swf";
_externalClass.addEventListener(Event.COMPLETE, onCompleteExternalClass);

private function onCompleteExternalClass(e:Event):void

	var c:Class;
	c = _externalClass.getClass("MyPrecompiledClass");
	var myvar:* = new c();

At this point you can access all the methods and properties from MyPrecompiledClass, as if it were another class.

Using ExternalFont the way the class works changes a bit, because all we need it’s to apply it to a TextField as soon as it loads. Previously so we can be able to use the font, it must be precompiled inside a swf, all this in a brand new .fla file; you must go to the library (F11), right click and add New Font, after this and compile it, you shall be able to access it via ExternalFont using the class name you give it via the window dialog:

import net.absulit.arbolnegro.data.ExternalFont;

private var _externalFont:ExternalFont;

_externalFont = new ExternalFont();
_externalFont.addEventListener(Event.COMPLETE, onCompleteExternalFont);			
_externalFont.path = 'Arial.swf';

private function onCompleteExternalFont(e:Event):void 
	_externalFont.setFont('Arial', mytext_txt);

To avoid confusions I preffer to use the same font type name to name the .swf and the class to load; so when I need the name, I take a look to the .swf and that is the name I need

One Response to “Loading external classes in precompiled swf

  1. […] This post was mentioned on Twitter by Sebastian Sanabria, Arbol Negro Dev Team. Arbol Negro Dev Team said: Loading external classes in precompiled #swf http://arbolnegro.absulit.net/?p=115 #as3 #flash […]

Leave a Reply


= 4 + 0

Switch to our mobile site