Copy link to clipboard
Copied
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 !
1 Correct answer
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);
}
Copy link to clipboard
Copied
You could animate the text by using a mask - growing the mask along each frame of animation.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
For pure AS3, you could just keep appending a new character (stored in an Array, perhaps) to a textfield with each keystroke:
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
Clay
This worked perfectly!!! Thanks for the scripting help!!!
Erik

