Welcome Guest [Log In] [Register]
Welcome to Brackenwood. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Now I Feel Really Dumb <(>_<)>; Controlling the timeline with keyboard
Topic Started: Apr 17 2005, 02:03 PM (87 Views)
KWarp
Member Avatar
Brackenwood Middleweight
I thought this would be really easy, but I suppose not. :(

Allright, what I wanna do is add some timeline control to the movie I made, but I figure buttons will both get in the way of the visual content and slow down the movie if I use alphas. So I figure, let's use the keyboard! :bing:

The problem I've hit is that I have no idea how to properly code the Keyboard to respond to my buttons. Here's what I've written on the first frame of my timeline:
Code:
 
//stop the movie with space bar
if(Key.isDown(Key.SPACE)) {
_root.stop();

I hope it's close. Any help?

Also, how would I check if the movie is playing or not? Is it something as simple as:
Code:
 
if(_root.play){
//do this code
} else{
//do this other code}

?
Offline Profile Quote Post Goto Top
 
ItsaMystery
Member Avatar
Brackenwood Lightweight
You're on the right track :)

First, make sure your movie is in a movie clip (you can give it an instance name of 'movie'). Then, off side of the stage, make another movie clip (just a little ball, or something of the sort; it doesn't really matter what it is, as long as it's a movie clip). Title this 'controller'.

Now, add this code into the controller movie clip:
Code:
 
onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE)) {
 _parent.movie.stop();
} else {
 _parent.movie.play();
}
}


Fairly simple, and should work for what you're trying to do! Hope that helps :)
Offline Profile Quote Post Goto Top
 
ItsaMystery
Member Avatar
Brackenwood Lightweight
While I'm at it...

Create a dynamic text box anywhere on the stage, and give it a var name of 'input'.

Now, plug in this new code to the controller movie clip:
Code:
 
onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE)) {
 _parent.movie.stop();
 _parent.input = "false";
} else {
 _parent.movie.play();
 _parent.input = "true";
}
}


If the movie is playing, the the text box will read 'true'. If it's stopped, it will read 'false'.

Good luck to you! :lol: :fpbls:
Offline Profile Quote Post Goto Top
 
KWarp
Member Avatar
Brackenwood Middleweight
Now that's quite useful. Although I really wanted the Spacebar to toggle the stop and play function. As in, push once: it stops, push again: it plays.

Also, if I wanted my movie to respond to any of the keys other than the constants like SPACE, DELETEKEY, etc, do I just need to type the actual key in the code?

Code:
 
onClipEvent (enterFrame) {
if (Key.isDown(5)) {
 gotoAndPlay("place5")
}
}


Will Flash recognize that as the "5" key on the keyboard, or does it need to be in quotes or something?
Offline Profile Quote Post Goto Top
 
mikepol
Member Avatar
Brackenwood Newbie
you need to look up the keycodes for each key on the keyboard... in the case of the number 5 the keycode is 101
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Actionscript · Next Topic »
Add Reply