custom type face class by dinesh?

Posted by dineshpeiris on Stack Overflow See other posts from Stack Overflow or by dineshpeiris
Published on 2010-04-09T08:51:08Z Indexed on 2010/04/09 8:53 UTC
Read the original article Hit count: 499

Filed under:
|

package typeface{ import flash.display.*; import flash.events.Event; import flash.filters.BitmapFilter; import flash.filters.BitmapFilterQuality; import flash.filters.BlurFilter;

public class Main extends Sprite {
    private var typeSet:String="SEE > THINK > CREATE";
    private var collectionSet:MovieClip;
    private var w:int = 1;

    public function Main():void {
        trace("start typeface application");            
        collectionSet = new MovieClip();
        for (var n:int = 0; n < typeSet.length; n++) {
            var _x:int = 0 + (40 * n);
            var _y:int = 0;
            var Type:TypeCollector = new TypeCollector(_x, _y, stringToCharacter(typeSet, n), collectionSet);
            Type.addEventListener("action", actionHandler);
        }       
        collectionSet.x = 100;
        collectionSet.y = (stage.stageHeight / 2) - 80;
        addChild(collectionSet);
    }
    private function actionHandler(event:Event):void {
        if (w == 16) {
            collectionSet.filters = [new BlurFilter(30, 30, BitmapFilterQuality.HIGH)];
            removeChild(collectionSet);
        }
        w++;
    }
    public function stringToCharacter(str:String, n:int):String {
        if (str.length == 1) {
            return str;
        }
        return str.slice(n, n+1);
    }
}

}

package typeface { import flash.display.*; import flash.events.Event; import flash.utils.Timer; import flash.events.TimerEvent; import flash.filters.BitmapFilter; import flash.filters.BitmapFilterQuality; import flash.filters.BlurFilter; import flash.events.EventDispatcher;

public class TypeCollector extends EventDispatcher {

    private var TYPE_MC:typeMC;
    private var typeArray:Array = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "<", ">");
    private var character:String;
    private var num:int = 0;
    private var TypeTimer:Timer;
    private var _xNum:int;
    private var _yNum:int;
    private var movieClip:MovieClip;

    public function TypeCollector(_x:int, _y:int, char:String, movie:MovieClip) {
        var totalNum:int = typeArray.length;            
        _xNum = _x;
        _yNum = _y;
        movieClip = movie;
        character = char;
        TypeTimer = new Timer(100, totalNum);
        TypeTimer.addEventListener("timer", TypeRoutTimer);
        TypeTimer.start();
    }   
    public function TypeRoutTimer(event:TimerEvent):void {
        CreateTypeFace(num, _xNum, _yNum, character);
        num++;
    }
    public function CreateTypeFace(num:int, _x:int, _y:int, character:String) {
        if (character == " ") {

        } else {
            if (TYPE_MC != null) {
                TYPE_MC.filters = [new BlurFilter(30, 30, BitmapFilterQuality.HIGH)];
                movieClip.removeChild(TYPE_MC);
            }           
            if (typeArray[num] == character) {
                TYPE_MC = new typeMC();
                TYPE_MC.x = _x;
                TYPE_MC.y = _y;
                TYPE_MC.typeTF.text = typeArray[num];
                TYPE_MC.filters = [new BlurFilter(5, 5, BitmapFilterQuality.HIGH)];
                movieClip.addChild(TYPE_MC);

                dispatchEvent(new Event("action"));

                TypeTimer.stop();
            } else {                
                TYPE_MC = new typeMC();
                TYPE_MC.x = _x;
                TYPE_MC.y = _y;
                TYPE_MC.typeTF.text = typeArray[num];
                TYPE_MC.filters = [new BlurFilter(10, 10, BitmapFilterQuality.HIGH)];
                movieClip.addChild(TYPE_MC);                
            }
        }
    }
}   

}

© Stack Overflow or respective owner

Related posts about flash

Related posts about as3