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!
Printable View
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):
and I got this error, Statement must appear within on/onClipEvent handler, for each line with a keyListener on it.Code:keyListener = new Object();
keyListener.onKeyDown = function() {
if (Key.getCode() == Key.SPACE) {
if (chest_mc.hitTest(_xmouse, _ymouse)) {
chest_mc.play();
}
}
};
Key.addListener(keyListener);
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!