Having problems with getting keyboard to control timeline

Hi guys,

I’m doing a Flash presentation for a client and they have requested that they be able to move forwards/backwards and play/stop with the arrow keys and spacebar respectively.

This has been doing my head in for about five days now so I was wondering if you could give me some advice as to why my syntax isn’t working properly (code posted below).

The arrow keys move to points in the presentation but don’t seem to go to the markers I have outlined in the code. I think I have got the spacebar to stop the movie - I just need to get it to play as well.

Any help would be much appreciated.

Thank you,

Flashead


import mx.utils.Delegate;



var nCheckPoint:Number = -1;

var aCheckPoints:Array = new Array();

aCheckPoints.push( { sScene:"001", nFrame:69 } );

aCheckPoints.push( { sScene:"002_003", nFrame:34 } );

aCheckPoints.push( { sScene:"002_003", nFrame:137 } );

aCheckPoints.push( { sScene:"002_003", nFrame:240 } );

aCheckPoints.push( { sScene:"002_003", nFrame:344 } );

aCheckPoints.push( { sScene:"004_005", nFrame:80 } );

aCheckPoints.push( { sScene:"004_005", nFrame:191 } );

aCheckPoints.push( { sScene:"004_005", nFrame:281 } );



var oListener:Object = new Object();

oListener.onKeyDown = Delegate.create(this, onKeyDown);

Key.removeListener(oListener);

Key.addListener(oListener);



function onKeyDown():Void

{

   switch(Key.getCode())

   {

   case Key.RIGHT:

      nCheckPoint++

      if(nCheckPoint >= aCheckPoints.length) {

          nCheckPoint = 0;

      }

      GoToCheckPoint(nCheckPoint);

      break;

   case Key.LEFT:

      nCheckPoint--;

      if(nCheckPoint < 0) {

          nCheckPoint = aCheckPoints.length - 1;

      }

      GoToCheckPoint(nCheckPoint);

      break;

   case Key.SPACE:

      stop();

      break;
    
   case Key.SPACE:

      play();

      break;

   default:

      trace("UNHANDLED KEY");

      break;

   }

}


function GoToCheckPoint(nValue:Number):Void

{

   var oChkPoint:Object = aCheckPoints[nValue];

   var sScene:String = oChkPoint["sScene"];

   var nFrame:Number = oChkPoint["nFrame"];

   gotoAndPlay("sScene", nFrame);

}