• home
  • forum
  • my
  • kt
  • download
  • Home / 2D Graphics / Flash / Games /

    Learn to move a movie clip with the arrow keys!

    Author: 2008-10-07 14:21:39 From:

    In this short tutorial i will explain how to move a movie clip with your arrow keys,
    To start you should have the movie clip that you want to be able to control with the arrow keys ready,
    We are now going to add the Actionscript to the movie clip, we need to select the movie clip and display the
    Actionscript panel you can do this by either pressing F9 or by going to window>actions,
    now copy and paste the following code in to it:

    onClipEvent(enterFrame){
    if(Key.isDown(Key.RIGHT)){
    this._x += 5;
    }
    if(Key.isDown(Key.LEFT)){
    this._x -= 5;
    }
    if(Key.isDown(Key.UP)){
    this._y -= 5;
    }
    if(Key.isDown(Key.DOWN)){
    this._y += 5;
    }
    }

    Code look confusing? don't worry about it, its pretty easy to understand heres a breakdown of what the code does.

    onClipEvent(enterFrame){

    This basically means that when this movieclip is present in the current frame do what is says in the brackets,

    if(Key.isDown(Key.LEFT)){

    This basically means if that key is down do what it says in the brackets,

    this._x -= 5;

    This means that the X coordinates are increased by 5,

    this._y += 5;

    This means that the Y coordinates are increased by 5,

    See simple wasnt it? you should now have something similar to this:

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      3D (20)
      Math Physics (14)
      3rd Party (5)
      Navigation (60)
      Actionscripting (26)
      Optimization (16)
      Animation (32)
      Projector (9)
      Audio (46)
      Special Effects (112)
      Backend (25)
      Text Effects (65)
      Drawing (18)
      Tips and Techniques (41)
      Dynamic Content (25)
      Tricks (6)
      Games (81)
      Utilities (21)
      Getting Started (91)
      Video (24)
      Interactivity (43)
      Web Design (29)

    New

    Hot