package { import flash.display.MovieClip; import flash.utils.Timer; import flash.events.TimerEvent; import flash.text.TextField; public class Typewriter extends MovieClip { public var flickerOn:Boolean = false; public var letters:Array = new Array(); public var timer:Timer = new Timer(250); public var betweenLines:String = "\n> "; public var delay:uint = 0; public function Typewriter():void { type("Hello and welcome to today's tutorial."); type("We hope you enjoy it."); type(" "); type("__ _"); type("|_ | /\\ |_ |_|"); type("| |_ / \\ _| | |"); timer.addEventListener(TimerEvent.TIMER,typeChar); timer.start(); } private function type(theString:String):void { letters.push(betweenLines); for (var i = 0; i < theString.length; i++) { letters.push(theString.charAt(i)); } } private function typeChar(e:TimerEvent):void { if ((letters[0] == betweenLines && delay < 8) || letters.length == 0) { delay++; if (flickerOn) { typed.text = typed.text.substring(0,typed.text.length - 1); } else { typed.appendText("_"); } flickerOn = !flickerOn; } else { delay = 0; typed.appendText(letters.shift()); } } } }