Skip to main content
Participating Frequently
July 11, 2019
Answered

Any keypress event =goto next frame

  • July 11, 2019
  • 3 replies
  • 2052 views

I'm trying to create a keypress event that would give the impression of somebody working on a keyboard and having their document appear onscreen real time as they type. No matter what key they press, they correct letters come up. I have received code to use and have tried snippets but Animate seems buggy (or maybe I am) but it doesn't seem to work.

​Basically I need any key pressed to move the playhead forward:

(snippet)​:

stop();

stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler);

function fl_KeyboardDownHandler(event:KeyboardEvent):void

{

nextFrame();

}

​(previous script):

stop();stage.addEventListener(KeyboardEvent.KEY_DOWN, changeSection);

function changeSection(event:KeyboardEvent):void {

nextFrame();

}

​nothing occurs.

​thank you in advance

    This topic has been closed for replies.
    Correct answer kglad

    click the stage with your mouse and then type.  any problems?

    3 replies

    firewahlAuthor
    Participating Frequently
    July 30, 2019

    id really like to be able utilize a different method to simulate the typing of this sort of text amount ( i am currently adding one letter to keyframe, I seem to recall being able to add a live text box somewhere and then have it access the embedded text from within the action script:

    Wi-Fi can provide you with added coverage in places where cell networks don't always work - like basements and apartments. No roaming fees for Wi-Fi connections also means you stay connected while travelling the world.

    firewahlAuthor
    Participating Frequently
    July 30, 2019

    I want the playhead to return to the beginning of the animation to reset the scene.

    would you happen to also know of a process that would take each letter of a paragraph and turn them into an object that could be placed into its own keyframe procedurally?

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    July 11, 2019

    click the stage with your mouse and then type.  any problems?

    firewahlAuthor
    Participating Frequently
    July 11, 2019

    nothing comes up

    kglad
    Community Expert
    Community Expert
    July 11, 2019

    what do you mean by 'nothing comes up'?  you're not going to see anything unless you have a multiframe main timeline with different content in each frame.

    if you want the text to appear in a textfield, you must create the textfield and the code to add text to it:

    stop();

    var alphaS:String="abcdefghijklmnopqrstuvwxyz";

    var tf:TextField=new TextField();

    addChild(tf);

    stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler);

    function fl_KeyboardDownHandler(event:KeyboardEvent):void

    {

    tf.appendText(alphaS.charAt(event.charCode-97));   // this will get you started with lowercase letters.

    }