Welcome, Guest
  • Author Topic: Problem with keylistener in AS2  (Read 1294 times)

    jass12

    • Server what's that
    • *
    • Posts: 2
      • View Profile
    Problem with keylistener in AS2
    « on: 05/02/11, 13:24 »
    Hi
    I would like to make in AS2 such event that goes on frame named "svi" if space bar is pressed, otherwise (pressing any other key) it should go to to frame named "one"

    This is my code and it doesn't work:


    var keyListener:Object = new Object();

    KeyListener.onKeyDown = function() {
       if (Key.getAscii() == 32) {
          gotoAndStop("svi");
       } else {
          gotoAndPlay("one");
       };
    };

    Key.addListener(keyListener);



    Can anybody help???

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: Problem with keylistener in AS2
    « Reply #1 on: 05/02/11, 14:07 »
    For a more accurate result use the constant provided in the Key class

    Code: [Select]
       if (Key.isDown(Key.SPACE)) {
          gotoAndStop("svi");
       } else {
          gotoAndPlay("one");
       };

    Also check that you're testing outside Flash IDE or you are disabling Keys from Control menu, since spacebar have a purpose inside Flash IDE

    Jorge

    jass12

    • Server what's that
    • *
    • Posts: 2
      • View Profile
    Re: Problem with keylistener in AS2
    « Reply #2 on: 05/11/11, 10:47 »
    Thanks, it works both ways now.

    I did mistake by naming KeyListener first with k, than with K...   ::)

    that case sensitive is driving me crazy sometimes....

    thanks again
    « Last Edit: 05/11/11, 10:49 by jass12 »