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

Type-on using AS3 - user taps any key & scripted text appears

Participant ,
Dec 03, 2018 Dec 03, 2018

i’m Wanting to be able to create type-on animations whereby no matter what key the user clicks on the keyboard (A thru Z, Space, Return) scripted text appears one character at a time.   (Note: by scripted I mean predetermined paragraph of text - not AS3 type script)

The idea being to simulate typing or data entry so that each key stroke animates an additional character in the string.

I’m new to AS3 and I’m unsure how to approach this task?

Thanks in advance for any advice you can land !

324
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 , Dec 03, 2018 Dec 03, 2018

Assuming you have a dynamic textfield on the stage named "myText":

var myString:String = "this is a test";

var chars:Number = 0;

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);

function keyHandler(event:KeyboardEvent):void {

    if (++chars === myString.length) {

        stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyHandler);

        trace("DONE!");

    }

    myText.text = myString.substr(0, chars);

}

Translate
Community Expert ,
Dec 03, 2018 Dec 03, 2018

You could animate the text by using a mask - growing the mask along each frame of animation.

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
Participant ,
Dec 03, 2018 Dec 03, 2018

Thank you for the suggestion.  I could also create each character as a separate image and script the movie to advance a frame on each keystroke but it’s labor intensive.

I’m Hoping there’s a more eloquent solution using AS3 whereby the characters are stored in a string - say - and animate to the stage in a field as key strokes register.

Thanks again for your input Joseph!

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
Community Expert ,
Dec 03, 2018 Dec 03, 2018

For pure AS3, you could just keep appending a new character (stored in an Array, perhaps) to a textfield with each keystroke:

TextField - Adobe ActionScript® 3 (AS3 ) API Reference

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 ,
Dec 03, 2018 Dec 03, 2018

Assuming you have a dynamic textfield on the stage named "myText":

var myString:String = "this is a test";

var chars:Number = 0;

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);

function keyHandler(event:KeyboardEvent):void {

    if (++chars === myString.length) {

        stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyHandler);

        trace("DONE!");

    }

    myText.text = myString.substr(0, chars);

}

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
Participant ,
Dec 03, 2018 Dec 03, 2018
LATEST

Clay

This worked perfectly!!!  Thanks for the scripting help!!!

Erik

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