-
Controlling MovieClips
Fairly inexperienced at anything other than basic scripting in Flash. What I'm trying to do is create a movie clip in AS2 that can be told to play by pressing the spacebar, but only when the mouse is over it. Any help would be appreciated!
-
my_mc is the instance name of the movie clip you want to play
Code:
keyListener = new Object();
keyListener.onKeyDown = function() {
if (Key.getCode() == Key.SPACE) {
if (my_mc.hitTest(_xmouse, _ymouse)) {
my_mc.play();
}
}
};
Key.addListener(keyListener);
-
Thanks dawsonk!
I tried attaching what you typed to the movieclip (chest is the name of my mc):
Code:
keyListener = new Object();
keyListener.onKeyDown = function() {
if (Key.getCode() == Key.SPACE) {
if (chest_mc.hitTest(_xmouse, _ymouse)) {
chest_mc.play();
}
}
};
Key.addListener(keyListener);
and I got this error, Statement must appear within on/onClipEvent handler, for each line with a keyListener on it.
When I attach the code to the frame I get no errors but nothing happens.
-
Okay, I got it! I didn't add the _mc to my movie clip name. Thanks dawsonk! I knew it would be a keylistener, but I just couldn't figure out exactly how to code it. This helped a lot!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|