A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: PLAY and Stop PLayhead using keyboard events in AS3

  1. #1
    Member
    Join Date
    Apr 2008
    Posts
    44

    PLAY and Stop PLayhead using keyboard events in AS3

    Hello,

    my problem is very simple. I want my animation to STOP when I press SPACE, and then PLAY when I press SHIFT. This needs to be in AS3. The only catch is that my whole animation is composed of 5 Scenes. Would this be a problem? Also, I'm confused as to where I should add the code. I have it in a class and it still doesnt work. I tried putting it on the 1st frame on Scene 1. Please reply ASAP.

  2. #2
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    Try this, placing the code in a class should be fine.

    Code:
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyBoardPress);
    
    function keyBoardPress(event:KeyboardEvent) {
        //Space bar press
        if (event.charCode == 32) {
        	stop();
        }
    	
        //Shift key press
        if (event.charCode == 16) {
    	 nextScene();	
        }
    }
    Last edited by ilike2; 02-03-2010 at 08:01 AM. Reason: typo

Tags for this Thread

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