# Pressing a key squence to goto next frame or scene

**URL:** https://forum.kirupa.com/t/pressing-a-key-squence-to-goto-next-frame-or-scene/263938
**Category:** Uncategorized
**Created:** [June 20, 2008, 5:35pm UTC](https://forum.kirupa.com/t/pressing-a-key-squence-to-goto-next-frame-or-scene/263938 "2008-06-20T17:35:31Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![bens19uk](https://avatars.discourse-cdn.com/v4/letter/b/7cd45c/32.png) [@bens19uk](https://forum.kirupa.com/u/bens19uk)
#### Post date: [June 20, 2008, 5:35pm UTC](https://forum.kirupa.com/t/pressing-a-key-squence-to-goto-next-frame-or-scene/263938/1 "2008-06-20T17:35:31Z")

</div>

Hi

Can any one tell me the actionscript 2 code to reconize a squence of key presses to trigger next frame or next scene.

thanx in advance  
Ben  
ps im try to learn action script 2

---

<div class="post-metadata">

### Author: ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)
#### Post date: [June 20, 2008, 7:46pm UTC](https://forum.kirupa.com/t/pressing-a-key-squence-to-goto-next-frame-or-scene/263938/2 "2008-06-20T19:46:30Z")

</div>

```auto
stop();
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
	if (Key.isDown(Key.SPACE) && Key.isDown(Key.UP)) {
		nextFrame();
	}
};
Key.addListener(keyListener);

```

---

<div class="post-metadata">

### Author: ![bens19uk](https://avatars.discourse-cdn.com/v4/letter/b/7cd45c/32.png) [@bens19uk](https://forum.kirupa.com/u/bens19uk)
#### Post date: [June 20, 2008, 9:23pm UTC](https://forum.kirupa.com/t/pressing-a-key-squence-to-goto-next-frame-or-scene/263938/3 "2008-06-20T21:23:38Z")

</div>

I need some info on this action script 2 language so I can work out how to use this code.  
Because I only know the basics soz lol language isnt my strong point but i would like to try master it. thanx again

[quote=glosrfc;2346533] ActionScript Code:

[COLOR=#0000FF]stop[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000] **var** [/COLOR] keyListener:[COLOR=#0000FF]Object[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000FF]Object[/COLOR]COLOR=#000000[/COLOR];  
keyListener.[COLOR=#0000FF]onKeyDown[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]isDown[/COLOR]COLOR=#000000[/COLOR] && [COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]isDown[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]nextFrame[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR];  
[COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]addListener[/COLOR]COLOR=#000000[/COLOR]; [/quote]

---

<div class="post-metadata">

### Author: ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)
#### Post date: [June 20, 2008, 9:38pm UTC](https://forum.kirupa.com/t/pressing-a-key-squence-to-goto-next-frame-or-scene/263938/4 "2008-06-20T21:38:32Z")

</div>

Info can be found by checking the keywords in the Flash help manual:  
keylistener  
onkeydown  
key.isdown  
addlistener  
nextframe

---

<div class="post-metadata">

### Author: ![bens19uk](https://avatars.discourse-cdn.com/v4/letter/b/7cd45c/32.png) [@bens19uk](https://forum.kirupa.com/u/bens19uk)
#### Post date: [June 20, 2008, 10:07pm UTC](https://forum.kirupa.com/t/pressing-a-key-squence-to-goto-next-frame-or-scene/263938/5 "2008-06-20T22:07:11Z")

</div>

Thanx for your help glosrfc.

I will master the action script language!!!

---

<div class="post-metadata">

### Author: ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)
#### Post date: [June 20, 2008, 11:12pm UTC](https://forum.kirupa.com/t/pressing-a-key-squence-to-goto-next-frame-or-scene/263938/6 "2008-06-20T23:12:23Z")

</div>

That’s the spirit…keep with it.

---

<div class="post-metadata">

### Author: ![bens19uk](https://avatars.discourse-cdn.com/v4/letter/b/7cd45c/32.png) [@bens19uk](https://forum.kirupa.com/u/bens19uk)
#### Post date: [June 21, 2008, 9:46am UTC](https://forum.kirupa.com/t/pressing-a-key-squence-to-goto-next-frame-or-scene/263938/7 "2008-06-21T09:46:24Z")

</div>

Sorry to bother you again you know in your example you have told it to look at the keyboard for the user to press space and up together. I want to use numbers in my “code” I look on the help menu of flash and found the key codes / ASCII key codes but I can find a example on how to use them. Also in your example you have to press them down at the same time is there a way of press one after an other.  
Thanx again Ben

[quote=glosrfc;2346533] ActionScript Code:  
[LEFT][COLOR=#0000FF]stop[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000] **var** [/COLOR] keyListener:[COLOR=#0000FF]Object[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000FF]Object[/COLOR]COLOR=#000000[/COLOR];  
keyListener.[COLOR=#0000FF]onKeyDown[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]isDown[/COLOR]COLOR=#000000[/COLOR] && [COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]isDown[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]nextFrame[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR];  
[COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]addListener[/COLOR]COLOR=#000000[/COLOR];  
[/LEFT]

[/quote]

---

<div class="post-metadata">

### Author: ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)
#### Post date: [June 21, 2008, 5:27pm UTC](https://forum.kirupa.com/t/pressing-a-key-squence-to-goto-next-frame-or-scene/263938/8 "2008-06-21T17:27:29Z")

</div>

Substitute the if statement with if (Key.isDown(53) && Key.isDown(55)) { where 53 is the key code for 5 and 55 is the key code for 7. Change the numbers to reflect the numbers you want to use.  
If you want to avoid holding them down at the same time, then you can assign the key codes to a variable and check against that. For example:  
var moveForward:String = “57”;  
var captureKeys:String = “”;  
stop();  
var keyListener:Object = new Object();  
keyListener.onKeyDown = function() {  
if (Key.isDown(53)) {  
captureKeys = captureKeys+“5”;  
}  
if (Key.isDown(55)) {  
captureKeys = captureKeys+“7”;  
}  
if (captureKeys == moveForward) {  
nextFrame();  
}  
};  
Key.addListener(keyListener);
