# Typewriter class delay "shade" text for 2 seconds

**URL:** <https://forum.kirupa.com/t/typewriter-class-delay-shade-text-for-2-seconds/246228>\
**Category:** Uncategorized\
**Created:** [December 8, 2007, 12:12pm UTC](https://forum.kirupa.com/t/typewriter-class-delay-shade-text-for-2-seconds/246228 "2007-12-08T12:12:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arn](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@arn](https://forum.kirupa.com/u/arn)\
**Post date:** [December 8, 2007, 12:12pm UTC](https://forum.kirupa.com/t/typewriter-class-delay-shade-text-for-2-seconds/246228/1 "2007-12-08T12:12:22Z")

</div>

Hi All,

Im using this group94 style typewriter class which loads it’s text from an xml file.

The class is almost perfect…exept for one thing.  
I would like to delay the “old” text with a few seconds…

At the moment the old text (reversed typing…) is finished typing at the same time the new text is…

I want to delay the old text with a few seconds so that when a new text is loaded  
and is finished typing you’ll see the old text typing out for an extra 2 or 3 seconds…

Can somenone help me out to modify the Class file?..

```auto

import mx.utils.Delegate;

class StrMotion{
    
    private var textoIn:String;
    private var textoOut:String;
    private var indexIn:Number;
    private var indexOut:Number;
    private var textfield:TextField;
    private var speed:Number;
    private var id:Number;
    private var duration:Number;
    private var time:Number;
    private var changeIn:Number;
    private var changeOut:Number;
    private var styles:TextField.StyleSheet;
        
    public function StrMotion(target:TextField, v:Number){
        textfield=target;
        duration=80;
        speed=v;
        styles = new TextField.StyleSheet();
        styles.setStyle("in", 
          {color:'#c4c4c4'}
        );
        styles.setStyle("out", 
          {color:'#666666'}
        );
        textfield.styleSheet=styles;
    }
    
    private function tw(t:Number, b:Number, c:Number, d:Number):Number {
        return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
    }
    
    public function showText(str:String):Void{
        time=0;
        clearInterval(id)
        textoIn=str;
        changeIn=str.length;
        textoOut=textfield.text;
        changeOut=textoOut.length;
        id=setInterval(Delegate.create(this,setText),speed);
    }
    private function getChar(str:String, index:Number):String{
        return str.substr(-index,index);
    }
    private function setText():Void{
        time++;
        indexIn=Math.floor(tw(time, 0, changeIn, duration));
        if (textoOut!=""){
            indexOut=Math.floor(tw(time, 0, changeOut, duration));
            //trace(getChar(textoOut,(textoOut.length-indexOut)))
        }
        //trace(indexIn+" :: "+" :: "+indexOut+" :: "+(textoOut.length-indexOut));
        textfield.htmlText="<in>"+getChar(textoIn,indexIn)+"</in>"+"<out>"+getChar(textoOut,(textoOut.length-indexOut))+"</out>";
        if (time>=duration){
            clearInterval(id);
        }
    }
}

```

put this in the fla.

```auto

miniyo.autoSize = "left";
miniyo.wordWrap = true;
miXML = new XML();
miXML.ignoreWhite = true;
miXML.onLoad = function() {

          var mystring:String = this.firstChild.childNodes.toString();

          var str:StrMotion = new StrMotion(miniyo, 40);

          str.showText(mystring);

      };
miXML.load('texto.xml');

```

Many thanks!

best

Arn
