WHAT'S NEW?
Loading...

package TypeWriterEvent as3


package com.PustakaFlash.text
{
 import com.PustakaFlash.events.TypeWriterEvent;
 import flash.text.TextField;
 import flash.utils.Timer;
 import flash.events.TimerEvent;
 /**
  * ...
  * @author Ricko
  */
 public class TypeWriter extends TextField
 {
  private var i:String;
  private var t:TextField;
  
  private var evt:TypeWriterEvent;
  private var c:uint;
  private var d:String;
  private var Ti:Timer;
  
  public function TypeWriter(a:String, Te:TextField)
  {
   i = a;
   t = Te;
  }
  
  private function doWrite(e:TimerEvent):void
  {
   t.text = i.substr(0, c);
   
   if (c <= i.length)
   {
    d = i.substr(c - 1, 1);
    c ++;
    evt = new TypeWriterEvent(TypeWriterEvent.TYPING, {characterCounter:c, currentCharacter:d});
    t.dispatchEvent(evt);
   }
   else
   {
    stop();
   }
  }
  
  
  public function start():void
  {
   Ti = new Timer(50);
   Ti.start();
   Ti.addEventListener(TimerEvent.TIMER, doWrite);
   evt = new TypeWriterEvent(TypeWriterEvent.START);
   t.dispatchEvent(evt);
  }
  
  public function stop():void
  {
   
   Ti.stop();
   Ti.removeEventListener(TimerEvent.TIMER, doWrite);
   Ti = null;
   c = 0;
   evt = new TypeWriterEvent(TypeWriterEvent.COMPLETE);
   t.dispatchEvent(evt);
  }
 }
}


package com.PustakaFlash.events
{

/**
  * ...
  * @author Ricko
  */
 import flash.events.Event;

 public class TypeWriterEvent extends Event
 {

  public static const START:String = "START";
  public static const TYPING:String = "TYPING";
  public static const COMPLETE:String = "COMPLETE";

  public var optionalParameters:Object;
  public function TypeWriterEvent(type:String, optionalParams:Object = null, bubbles:Boolean = false, cancelable:Boolean = false):void
  {
   super(type, bubbles, cancelable);
   this.optionalParameters = optionalParams;
  }
  public override function clone():Event
  {
   return new TypeWriterEvent(type, this.optionalParameters, bubbles, cancelable);
  }
 }
}