> > Tutorials > T1075

Key Events.

Click the circle below to activate it and use arrow keys to move it around.


Download source project (3 kb)

  1. Launch Alligator Flash Designer and choose Blank
  2. Set movie dimensions to 500 x 200 (or any desired) with Frame > Frame Size
  3. Change frame delay to “Stop”.
  4. Choose Sprite tool and draw a sprite, inside the sprite draw an ellipse, hold Ctrl to draw a cricle
  5. Hit Esc to quit the sprite
  6. Choose Frame > ActionScript and paste the script
    function moveobject(){    if(Key.isDown(Key.RIGHT)){          Sprite1._x = Sprite1._x + 5;     }     if(Key.isDown(Key.LEFT)){          Sprite1._x = Sprite1._x - 5;     }     if(Key.isDown(Key.UP)){          Sprite1._y = Sprite1._y - 5;     }     if(Key.isDown(Key.DOWN)){          Sprite1._y = Sprite1._y + 5;     }}setInterval(moveobject,50);

    setInterval causes the Frame to execute the “moveobject” function every 50 milliseconds. The “moveobject” function checks if one of the arrow keys
    is pressed and then moves the Sprite1 object accordingly.

  7. Hit F9 for preview. Click anywhere inside to animation so it will be activated and start taking key strokes.
  8. Use arrow keys to move the circle around

get flash