1 Reply Latest reply on Sep 13, 2013 10:31 PM by NatMax

    Keyboard events

    JBMason

      Hey guys

       

      (warning: I'm a bit of a novice with flash)

       

      I have an assigment where we are to create 4 animations

      (1 walk, 1 jump, 1 sneak, 1 sprint) Which I have done... but not very well..

       

      The end product will be a HTMl document with the SWF embeded

      The 4 animations will be on a section of the page and will be controlled by the keyboard

      So an example is the walk animation will play when the up arrow is pressed.

       

      Having trouble with the actionscript, im not sure where to begin (Teacher's help is worthless!)

      Right now I have 4 Animations in seperate files and a final FLA. with a background and a large white space for the animations to sit

       

       

      If this isnt the right place to be asking this question

      could someone point me in the right direction?

       

      If someone could help me out...it would make my day....

        • 1. Re: Keyboard events
          NatMax

          Hello,

           

          As a prograsmmmer I would do something more complex but this could be done using technique below.

           

          As a new user you could go old school.

          Imagine all 4 animations on one timeline, and your code just makes the animation jump around from one section to another.

           

          From frame 1-10 is first animation. LEFT

          11-20 is next, UP and so on.  21-30 RIGHT and 31-40 DOWN.

           

          on a second layer called Actions, insert keyframe on frame 10, then put a "goto(1)" on frame 10 in script window. This will cause movie to loop back to first frame when it hits frame 10.  Looping.

           

          Then insert keyframe on frame 20 then put a "goto(11)" on frame 20 in script window.

           

          Then insert keyframe on frame 30 then put a "goto(21)" on frame 30 in script window.

           

          Then insert keyframe on frame 40 then put a "goto(31)" on frame 40 in script window.

           

          use a script that says...

          if you click left button go to and play frame 1,

          Up got to and play frame 11.

           

          I like to add another layer "Lables" and you can insert labels on frames with names to use in the go to statements instead of numbers. But number work well too.

           

          In review.

          Make all 4 animation loops inside one movie clip which is sitting on the main timeline.

           

          Make sure to name the movieclip in the properties window so you can talk to it.

          Call clip something like "gameSprite1"

           

          http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9 b90204-7d01.html

           

           

          KeyKey codeASCII key code

          Left Arrow

          37

          0

          Up Arrow

          38

          0

          Right Arrow

          39

          0

          Down Arrow

          40

          0

           

          Good example from Republic of Code

          http://www.republicofcode.com/tutorials/flash/as3keyboard/2.php

           

          I hope this helps.

          1 person found this helpful