1 Reply Latest reply on Sep 10, 2009 4:56 AM by Ned Murphy

    Spacebar as pause button? (AS 2)

    okaykiddo

      Hey guys, hoping someone can help me here. I'm trying to code the space bar key as a pause/play function in my flv player. I'm using Lee Brimlow's flv player tutorial as a model for my flv player so essentially it's driven via netstream coding. I've tried two different codes, code 1 being something I used a while back on another project and code 2 something I've been trying (hoping) would work better. If anyone has ANY advice please feel free to hit me up.

      Thanks in advance!

       

       

      Code:

       

      //1)

       

      onEnterFrame = function()
      {
          check_keys();
      }

       

      function check_keys()
      {
          if(!Key.isDown(Key.SPACE))
          {
              ns.pause();
              }
      }

       

      //2)

       

      stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown)
      function keyDown()
      {
          if (!Key.isDown(key.SPACE))
          {
              if (ns.pause(false)
              ns.pause(true)
          }
             
              else
          {
              ns.pause(false)
          }
      }

        • 1. Re: Spacebar as pause button? (AS 2)
          Ned Murphy Adobe Community Professional & MVP

          The second bit of code appears to be AS3, so the first thing you'll need to determine is what version of code is your file using.

           

          If the intent is AS2, then you can do a similar form of monitoring with the following code....

           

          var keyListener:Object = new Object();
          Key.addListener(keyListener);

           

          keyListener.onKeyUp = function(){
          if(Key.getCode() == 32){

               // process your ns command

          }
          }

           

          I am unfamiliar with ns in AS2, so I didn't offer detecting between paused or not.  If detecting it is not an option, you could use a boolean variable to establish the current pause status and use that

          1 person found this helpful