Skip to content

Instantly share code, notes, and snippets.

/s

Created October 10, 2013 12:53
Show Gist options
  • Save anonymous/6917850 to your computer and use it in GitHub Desktop.
Save anonymous/6917850 to your computer and use it in GitHub Desktop.
package Other{
import fl.controls.TextArea;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class AutoType{
private var typeSpeed=5;
private var msgArray:Array;
private var tArea:TextArea;
private var sTimer:Timer;
private var i=0;
public function AutoType(){
trace("AutoTyper has been loaded.");
}
public function sendMsg(Msg:String,textArea:TextArea):void{
tArea=textArea;
msgArray=Msg.split("");
sTimer=new Timer(typeSpeed*10, 1);
sTimer.addEventListener(TimerEvent.TIMER, sendTMSG);
sTimer.start();
}
public function setTextArea(textArea:TextArea):void{
tArea=textArea;
}
public function changeSpeed(speed:Number):void{
if(speed>10){
sendMsg("Error: You may only choose a speed between 1 and 10.", tArea);
}else if(speed<1){
sendMsg("Error: You may only choose a speed between 1 and 10.", tArea);
}else{
sendMsg("Information: Speed was just changed from "+typeSpeed+" to "+speed+".", tArea);
typeSpeed=speed;
}
}
private function sendTMSG(e:TimerEvent):void{
if(i!=msgArray.length){
tArea.verticalScrollPosition=tArea.maxVerticalScrollPosition;
tArea.text+=msgArray[i];
i++;
continueProcess();
}else{
tArea.verticalScrollPosition=tArea.maxVerticalScrollPosition;
if(msgArray[i-1]!="."){
tArea.text+=".";
}
tArea.text+="\n";
i=0;
}
}
private function continueProcess():void{
sTimer.reset();
sTimer.start();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment