Flash 5 Key.ENTER

Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

Hello,
how do I get my flash program to play when the ENTER key is pressed. Any key would be better though. I figured it was something like

on(Key.ENTER) {
play();
}

but, like always, I was wrong.

Pimpin like a pimp with an electrofied pimpin machine!

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

Figured it out! Took a couple minutes (and I'm supposed to be working but whatever....)

The onClipEvent action allows you to start an action on keydown. The problem is that this only seems to work on movie clips, so what you have to do is make a movie clip and apply the onClipEvent to it. Then set your actions to apply to the root movie rather than the movie clip. So your script will look like this:

Applied to a movie clip:

onClipEvent (keyDown) {
_root.play();
}

Hey, there's another way to do this too. The on (mouseover) event allows you to change your on event to keypress. So there you can select which key to use (doesn't seem to want to let me select nothing though) and do basically the same thing.

Applied to a button:

on (keyPress "") {
_root.play();
}

The only real difference here is that onClipEvent allows you to use any key while on (KeyPress) requires a specific key to be used.

Does this work for you? You were close Smiling

Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

Megan,
You are the peanut butter that makes me jam =). How about we get 10 gallons of ice cream, some whip cream (in the can), and a bowl of heated chocolate (nestle' works best) and really get flashing =).

hehe...
thanks megan, I can always count on TWF members.
ken elliott

Pimpin like a pimp with an electrofied pimpin machine!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.