View Full Version : Press key and go to next scene

07-04-2007, 11:46 AM
Hi there,

Forgive me, but I'm very much a n00b when it comes to Action Script. I have been looking around at tutorials and searched this and other sites...but I haven't been able to solve the problem. I'm working with Flash MX 2004, which I think runs Action Script 2.0.

Here's what I want to do: to be able to press the "Up" key on my keyboard which will then take me to the start of the next scene.

So far, I've just been playing around with this bit of code, which is attached to a small red circle which I converted to a movie clip.

if (Key.isDown(Key.UP)){
gotoAndPlay("Anxious 2", 1);

Note that Anxious 2 is the name of the next scene. I've been able to do other stuff with this code (such as stop the sounds playing), but not go to the next scene.

I hope that's enough detail.

Cheers and thanks!

07-04-2007, 12:01 PM
var keyListener:Object = new Object();
keyListener.onKeyUp = function() {
// trace("UP -> Code: "+Key.getCode()+"\tASCII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));
gotoAndPlay("Anxious 2", 1);

there are also two methods with may be usefull for you


07-04-2007, 12:11 PM
Hmm, thanks but that didn't seem to work. Here's the error log from that code if it helps.

**Error** Scene=Anxious1, layer=controls, frame=1:Line 1: Statement must appear within on/onClipEvent handler
var keyListener:Object = new Object();

**Error** Scene=Anxious1, layer=controls, frame=1:Line 2: Statement must appear within on/onClipEvent handler
keyListener.onKeyUp = function() {

**Error** Scene=Anxious1, layer=controls, frame=1:Line 6: Statement must appear within on/onClipEvent handler

Total ActionScript Errors: 3 Reported Errors: 3

07-04-2007, 12:37 PM
The reason seems to be that you've inserted Panel's suggested code on a symbol, rather than on a frame action...
Take it off the symbol, right-click the first frame of your movie, and select Actions. Make sure the window that pops up has Actions - Frame as title.

It would also be better to not target a scene's name, but only a targeted labeled frame in that scene. Thus label the first frame of your Anxious 2 scene with a label such as my_target1, add _level0, _root or a relative path to the main timeline, and only target the labeled frame on your script...


07-04-2007, 12:40 PM
put code on frame (not on object).

07-04-2007, 03:54 PM
Oh wicked, that did it!

Many thanks to you all. You rock!

07-04-2007, 05:43 PM