Simple Loader with AS3 and TweenMax

This a loader that I created for my OSMF-based player. This is lightweight and simple to use.
Colors and shapes can easily be customized, text could also be included and event animated to match blocks.

The creation function, simple drawing.

[cc lang=”actionscript”]public function createLoader(bgColor:uint=0x2e2e2e):void
this.x = 0;
this.y = 0;
bg = new Sprite();,1);,0xf7f7f7,1,true);,0,200,100,5,5,5,5);;
var gap:Number = 45;
var block:Sprite;

for(var i:int = 0;i<6;i++){ block = new Sprite();,1);,0x7e7e7e,1,false);*i),40,9,22);; bg.addChild(block); } this.addChild(bg); tint(); [/cc] And the function that handles the animation, it applies colorization to each block in order then calls it self with the index increased by one. [cc lang="actionscript"] private function tint(value:Number=0):void { var length:Number = bg.numChildren; var indexItem:Number; for(var i:int = 0;ilength-1) { indexItem = 0; } else { indexItem = value; }, .2, {colorMatrixFilter:{colorize:0x3399ff, amount:1.2, contrast:1, brightness:1, saturation:1, hue:50}, onComplete:function(){, .6, {colorMatrixFilter:{colorize:0xffffff, amount:1}, ease:Quad.easeInOut}); tint(indexItem+1); }}); }[/cc] The release version is a mere 20kb file. Download the source here: UILoader

View Example here: UILoader-Demo


Create a button with font-icon and pure actionscript 3

As I see that the font-icon technique is becoming very popular, and I personally like it very much I decided to post some code of how to create a simple button with an Icon using only AS3 as it is lighter and much faster on mobile devices.

We will create a class that will hold our button, as you will see I have embedded the signify font, (signify is a font which has icons corresponding to letters and numbers):

[cc lang=”Actionscript”]
import flash.display.GradientType;
import flash.display.Shape;
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.getQualifiedClassName;

public class UIButton extends Sprite
[Embed(source=”fonts/signify-webfont.ttf”, fontFamily=”Signify”, embedAsCFF=”false”)]
public static var signify:String;

private var myShape:Shape;
private var gradientBoxMatrix:Matrix;
private var masterWidth:Number;
private var masterHeight:Number;

private var radius:Number = 10;

public function UIButton()

Next we will create the main function that draws the button:

[cc lang=”Actionscript”]
public function createButton(gradientColor_:Array = null, width:Number=120, height:Number=60, x:Number=10, y:Number=10, _text:String = ‘E’)


First we draw the matrix for the gradients and the rectangle:

[cc lang=”Actionscript”]
myShape = new Shape();
gradientBoxMatrix = new Matrix();
gradientBoxMatrix.createGradientBox(width, height, Math.PI/2, 0, 0);, gradientColor_, [1,1,1], [0,128,255],gradientBoxMatrix);, 0x1e1e1e);,0,width,height,radius);;

And now we create the icon:

[cc lang=”Actionscript”]
var tfl:TextField = new TextField();
tfl.text = _text;
tfl.width = width/2;
tfl.height = height/2;
tfl.textColor = 0x0e0e0e;
tfl.embedFonts = true;
var tf:TextFormat = new TextFormat(‘Signify’,38,0x0e0e0e); //here we define the embedded font
tfl.selectable = false;

tfl.x = width/2 – tfl.textWidth+19;
tfl.y = -10;

finally we add them to the display object:

[cc lang=”Actionscript”]

we can easily call this class by doing:

[cc lang=”Actionscript”]
var button:UIButton = new UIButton();

View an example here: MobileUI