Easy question. But annoying enough

I am a flash newbie going over the ActionScript line by line now. Is it written terribly or it’s just me dumb?! Please take a look at my question: To create keyboard controls for a movie, I am supposed to add the following code to a movie clip:
onClipEvent(keyDown) {
if (Key.getCode() == 32) {
nextFrame();
}
}
This is all from the tutorial. Well, I guess I had to add a second frame to the Main Timeline. So I did by adding an animated movie clip to the second frame.
Now you probably will see that the two movie clips will keep flashing on the screen as the playhead keeps entering the first and second frames repeated.
I then had to add a frame action “stop()” to the first frame. But then, it won’t work at all. What I get is simply the very first frame. No matter what I do, nothing ever happens.
Where is the problem? Thank you very much!

what kind of key controls are you after? frame navigation? movement? other?

I would guess it’s navigation. Many thanks!

  1. Id put it in onClipEvent(enterFrame) so its not just on key down (unless you want only once perclick, then keydown is ok, depends on what you want and you really didnt seem to sure of that yourself)
  2. if thats an arrow key (32 and Im pretty sure it is) just use its Key constant:
    if (Key.isDown(Key.RIGHT)){
    nextFrame();
    }
  3. if you are controlling THAT movieclip, the previous code works fine, but if you want to effect the main timeline, you have to use _root. before the nextFrame() ie
    _root.nextFrame();
    so it will effect the main timeline and not that movieclip (which it will normally do since that code is ON that movieclip)

Thank you very much. I think I have pretty much figured out how it works. Well then, it is not about navigation on the main timeline. There is one thing I would like to say – that tutorial sucks big time!

Used as the parameter of onClipEvent, what is the difference between enterFrame and keyDown? Thanks!

enterframe happens every frame, keyDown only happens when the key is pressed. enterframe makes for a smooth playing animation while keydown would go frame by frame for every timethe key was pressed. Be aware that holding the key down will make keydown happen really fast as well, like me pressing and holding the A key aaaaaaaaaaaaaaaaaaaaaaa. Same will happen with any key and keyDown will react to that. This kind of iteration isnt as smooth as enterFrame though.

Got it. Now it starts to make sense! Many thanks for your great help!