Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Typewriter effect skip to end

New Here ,
Aug 16, 2014 Aug 16, 2014

Ok so this has been bugging me for awhile a so far I've ignored it because it's not a huge deal but I have a type writer effect using the code below, the problem is I want, when a button is clicked, for it to finish completely. Just jump right to the end. Basically the typing starts and then when said button is clicked, it displays all the text as opposed to just stopping in the middle or heading to the next frame.

I've seen ways to restart it, ways to stop it in the middle, but I've yet to see a way for it to quickly finish. I don't care if I need to replace the code I'd just like to be able to do this.

--------------

var mySound:Sound = new kb(); 

var mySoundChannel:SoundChannel = mySound.play(0);

import flash.utils.Timer;

import flash.events.TimerEvent;

var i=0;

var myString:String = "Text here shows up in text box"

var mytimer:Timer = new Timer(10,myString.length);

mytimer.addEventListener(TimerEvent.TIMER, timerHandler);

mytimer.start();

function timerHandler(event:TimerEvent):void{

T1.appendText (myString.charAt(i));

i++;

if (i==myString.length){mySoundChannel.stop();}

}

TOPICS
ActionScript
910
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 17, 2014 Aug 17, 2014

All you should need to do is stop the Timer and then assign the entire string to the textfield.  So in whatever event handler you have for the button....

mytimer.stop();

T1.text = myString;

Translate
LEGEND ,
Aug 17, 2014 Aug 17, 2014

All you should need to do is stop the Timer and then assign the entire string to the textfield.  So in whatever event handler you have for the button....

mytimer.stop();

T1.text = myString;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2014 Aug 17, 2014

Oh thank you, this helped a lot. For the code I used

button.addEventListener(MouseEvent.CLICK, stops);

function stops(e:MouseEvent)

{

mytimer.stop();

T1.text = myString;

if (mytimer.stop){mySoundChannel.stop();}

}

and it works great, but I seem to be having a little bug. When the button is clicked my text "jumps" up by a whole line. It seems that the code that holds the text is in fact not starting at the very start of the text box but one line below it. I've been poking around but I'm unsure what's causing this gap. Is there a way fix this or have when the button is clicked the text jump down by one line?

Edit: I know I can make it by doing

T1.text = "\nTexthere"

But there has to be a better way somewhere.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2014 Aug 17, 2014

Textfield for some odd reason seem to have a carriage return even though you never asked for one.  What you might try is to just assign an empty string to the textfield to start things off.

T1.text = "";

If that doesn't work then I know there is a way to do it that involves emptying the textfield.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2014 Aug 17, 2014

Thank you it worked like a charm! It's quite odd that it does that but at least the fix is just a short line of code. Thank you again you were a big help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2014 Aug 17, 2014
LATEST

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines