Skip navigation
rleach26
Currently Being Moderated

New to Actionscript 3

Apr 14, 2012 9:14 AM

I am new to actionscript 3.  I have text appearing in a text field with the appearence of a typewriter effect. How do I write the code so that present text after a 3 second delay is replaced by new text?

 
Replies
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 14, 2012 9:42 AM   in reply to rleach26

    use a timer.  i assume you have a function (eg, twEffectF) or class that accepts the text you want displayed with that effect and accepts the textfield (eg, tf) where you want that displayed.  if so, use:

     

    var textA:Array=["first string to display","next string","last string"] ;

    var t:Timer=new Timer(3000,0);

    t.addEventListener(TimerEvent.TIMER,timerF);

    t.start();

     

    function timerF(e:TimerEvent):void{

    tsEffectF(tf,textA[(Timer(e.currentTarget).repeatCount-1)%textA.length ]);

    }

     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 14, 2012 3:11 PM   in reply to kglad

    use:

     

     

    var textA:Array=["first string to display","next string","last string"] ;

    var t:Timer=new Timer(3000,0);

    t.addEventListener(TimerEvent.TIMER,timerF);

    t.start();

     

    function timerF(e:TimerEvent):void{

    twEffectF(textA[(Timer(e.currentTarget).repeatCount-1)%textA.length ]);

    }

    function twEffect(s:String):void{

    textField.text="";

    this.myArray=s.split("");

    addEventListener(Event.ENTER_FRAME,frameHandler);

    }

     

    function frameHandler(event:Event):void{

     

      if(myArray.length > 0) {

       textField.appendText(myArray.shift());

       

      }

      else

      {

       removeEventListener(Event.ENTER_FRAME, frameHandler);

       

      textField.text="";

      }

        }

     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 15, 2012 7:27 AM   in reply to rleach26

    use:

     

    var textA:Array=["first string to display","next string","last string"];

    var myArray:Array = [];

    var t:Timer=new Timer(3000,0);

    t.addEventListener(TimerEvent.TIMER,timerF);

    t.start();

     

    function timerF(e:TimerEvent):void {

        twEffectF(textA[(Timer(e.currentTarget).currentCount-1)%textA.length ]);

    }

    function twEffectF(s:String):void {

        trace(1,s,2)

        textField.text="";

        myArray=s.split("");

        addEventListener(Event.ENTER_FRAME,frameHandler);

    }

     

    function frameHandler(event:Event):void {

        if (myArray.length>0) {

            textField.appendText(myArray.shift());

        } else {

            removeEventListener(Event.ENTER_FRAME, frameHandler);

            textField.text="";

        }

    }

     

    p.s.  please mark helpful/correct responses, if there are any.

     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 15, 2012 1:06 PM   in reply to rleach26

    p.s.  please mark helpful/correct responses, if there are any.

     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 15, 2012 10:33 PM   in reply to rleach26

    use:

     

    var textA:Array=["first string to display","next string","last string"];

    var myArray:Array = [];

    var t:Timer=new Timer(3000,textA.length);

    t.addEventListener(TimerEvent.TIMER,timerF);

    t.start();

     

    function timerF(e:TimerEvent):void {

        twEffectF(textA[(Timer(e.currentTarget).currentCount-1)%textA.length ]);

    }

    function twEffectF(s:String):void {

        trace(1,s,2)

        textField.text="";

        myArray=s.split("");

        addEventListener(Event.ENTER_FRAME,frameHandler);

    }

     

    function frameHandler(event:Event):void {

        if (myArray.length>0) {

            textField.appendText(myArray.shift());

        } else {

            removeEventListener(Event.ENTER_FRAME, frameHandler);

            textField.text="";

        }

    }

     

    p.s.  you should mark the actual correct and helpful answers, not just any response of mine.  other people use those as shortcuts to find answers quickly, especially the correct answer which is linked in your original post.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points