dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: interaction with the key board: moving something with arrow keys

  1. #1
    Banned
    Join Date
    May 2005
    Posts
    31

    interaction with the key board: moving something with arrow keys

    How can you program in flash so that you can use the arrow keys to control where an object moves (like a game). If you can help me, please give me an explaination of what you are doing because I am not ery good a flash. My flash version is Flash MX 2004.

    Thanx everybody!

  2. #2
    Member
    Join Date
    Jun 2005
    Posts
    71
    on (keyPress "<Left>") {ur code here
    }
    u can use Right,Up,Down ,etc.. in the place of Left

  3. #3
    Banned
    Join Date
    May 2005
    Posts
    31
    i know but wut is "Ur code" if say, you wanted some movie clip to move up when you click the up arrow key.?

  4. #4
    Member
    Join Date
    Jun 2005
    Posts
    71
    create a movieclip and give it a instance name "car"
    speed = 10;
    car.onEnterFrame = function() {
    with (car) {
    if (Key.isDown(Key.RIGHT)) {
    _x += speed;
    if (_x >= 339) {
    _x = 339;
    }

    }


    else if(Key.isDown(Key.LEFT)){
    _x-=speed;
    if(_x<60){
    _x=60;
    }

    }

    else if(Key.isDown(Key.UP)){
    _y-=speed;
    if(_y<114){
    _y=114;
    }

    }
    else if(Key.isDown(Key.DOWN)){
    _y+=speed;
    if(_y>244)
    {
    _y=244;
    }

    }
    }
    }
    try this code it will move ur mc according to the keypress

  5. #5
    Member
    Join Date
    Jun 2005
    Posts
    71
    create a movieclip and give it a instance name "car"
    insert this code in the frame.
    code,

    speed = 10;
    car.onEnterFrame = function() {
    with (car) {
    if (Key.isDown(Key.RIGHT)) {
    _x += speed;
    if (_x >= 339) {
    _x = 339;
    }

    }


    else if(Key.isDown(Key.LEFT)){
    _x-=speed;
    if(_x<60){
    _x=60;
    }

    }

    else if(Key.isDown(Key.UP)){
    _y-=speed;
    if(_y<114){
    _y=114;
    }

    }
    else if(Key.isDown(Key.DOWN)){
    _y+=speed;
    if(_y>244)
    {
    _y=244;
    }

    }
    }
    }
    try this code it will move ur mc according to the keypress

  6. #6
    Banned
    Join Date
    May 2005
    Posts
    31
    thanx a bunch

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center