1 Reply Latest reply on Aug 29, 2006 8:38 AM by Newsgroup_User

    Key down, Key up, Key code problems

    Cole_UK
      I've been having problems putting a key down handler together, which is weird because it's pretty basic.

      on keydown

      if (_key.keycode = 4) then baOpenFile( the moviepath & "help\help.pdf" , "maximised" )

      end keydown

      doesn't seem to do anything, key up the same. I know this is a pretty basic thing, and in MX 2004 which is the Director version I'm using, they've done it a little different but I can't seem to see why it's not working.

      help?!
        • 1. Re: Key down, Key up, Key code problems
          Level 7
          Key functions operate in several different ways in Director. If you have
          an editable field or text member, then you can attach a behavior to that
          field or text sprite and include an on keyDown me and/or on keyUp me
          function. Because there is an editable sprite on the stage, Director
          will route key events to that sprite. If there is a function to handle
          the event, then something will happen. This sort of thing is usually
          done if you need to read and/or filter the user's input. You don't need
          a behavior at all if you just want the user to input something.

          If you are using key events for some other action, like navigation or
          game element control, then you need to tell Director to pay attention to
          the keyboard input. This is done by assigning a function as the
          keyDownScript or the keyUpScript. The assignment may be done in a movie
          event function, like startMovie, or it may be done in a behavior.

          Here's one example in a movie script window:

          on startMovie
          the keyDownScript = "readKeys"
          end

          on readKeys
          case the keyCode of
          4: baOpenFile(the moviePath & "help\help.pdf","maximised")
          end case
          end


          Here's an example in a behavior:

          property thisSprite

          on beginSprite me
          thisSprite = me.spriteNum
          the keyDownScript = "readKeys"
          end

          on endSprite me
          the keyDownScript = ""
          end


          In the second example, the behavior could be attached to any sprite that
          will be available when you want the key events to be interpreted.
          Setting the keyDownScript to "" will stop Director from paying attention
          to key events.

          --
          Rob
          _______
          Rob Dillon
          Adobe Community Expert
          http://www.ddg-designs.com
          412-243-9119

          http://www.macromedia.com/software/trial/