February 20th, 2011 / Author: Sebastián Sanabria Díaz
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:
var _externalClass: ExternalClass;
_externalClass = new ExternalClass();
_externalClass.path = "MyPrecompiledClass.swf";
private function onCompleteExternalClass(e:Event):void
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:
private var _externalFont:ExternalFont;
_externalFont = new ExternalFont();
_externalFont.path = 'Arial.swf';
private function onCompleteExternalFont(e:Event):void
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
July 2nd, 2010 / Author: Sebastián Sanabria Díaz
One of the most repetitive processes when using flash is loading images.
At the time of loading an image, you have to call several class to load a single image, and repeat the process can be confusing, if there is no class that handles the concept of image.
Usually when loading an image with Loader, it is placed inside a Sprite, so by default, SimpleImage is a Sprite, but you can also access the loaded content in the form of DisplayObject.
The following example also shows an image loaded twice through SimpleImage, both have been rotated 45 and scaled to 2.5, the image on the right has enabled smooth property to avoid pixelation of the image.
_simpleImage = new SimpleImage();
_simpleImage.x = 500;
_simpleImage.rotation = 45;
_simpleImage.path = _ocean;
_simpleImage.scaleX = 2.5;
_simpleImage.scaleY = 2.5;
_simpleImage.smooth = true;
fig1. Left image pixelated, right image softened
The idea of using smooth is because sometimes the size of the image is not correct, is of low quality, and so we reduce the errors.
The advantages of using SimpleImage will be reflected in time savings, moreover, to be used as a Sprite, which means you can manipulate in any manner permitted by this one, or convert to MovieClip, scale, filters, create masks.
SimpleImage also has the ability to read the progress of the data stream to find out the percentage loaded.
Download example files:
May 27th, 2010 / Author: Sebastián Sanabria Díaz
One of the most common task in actionscript in loading XML, it is the native way to load complex data; but there is a time when this process become a little anoying, because as you remember, in as2, load XML was just a couple of lines; in as3 is not that hard, but there are a couple of separate steps to load it and it’s sometimes confusing for begginers.
I have created XMLHandler to carry on those repetitions to “the easy way”, here is an example:
* @author Sebastián Sanabria Díaz
public class Main extends MovieClip
private var _xmlHandler:XMLHandler
public function Main()
_xmlHandler = new XMLHandler();
_xmlHandler.path = "data.xml";
private function onProgressEvent(e:ProgressEvent):void
trace(e.bytesLoaded / e.bytesTotal);
private function onCompleteXMLHandler(e:Event):void
//trace(e.target.xml);//using event parameter
trace(_xmlHandler.xml);//using the private var
This is a very simple example, loads XML, traces it, also shows its progress, which in a bigger XML file will be more useful.
Download example files:
May 25th, 2010 / Author: Sebastián Sanabria Díaz
Hi, my name is Sebastian Sanabria-Diaz, I’m a developer and today I wish to share under the GPL3 License, the actionscript3 code on wich I’ve been working and believe will help to many people who develop for Flash ActionScript3.
The general purpose of this project is to raise the level of skills, removing some repetitive work, sometimes removing simple steps, but too a big amount of repetitive steps and putting all into a single class.
There is XMLHandler wich handles a bit easier XML, joining a couple of steps into a single one, handling too events and errors.
Also CircularList wich is an endless-Array with features like: paging, to easy create a gallery.
Today may 25 I’m presenting a piece of this project, it is not complete, there is a lot more comming, but for reasons of time, I havent cleaned it completely; also is not completely documented, so first I’ll show examples before upload a full documented code.
Try the code, you can comment, if you consider that something is missing you can tell me, report error or bugs, you can do it here, or at the google project main page.
Go to Arbol Negro at Google Code