PDA

View Full Version : Stop MC on key up


smatmx
09-07-2005, 02:03 PM
How can you stop a MC when you release some keys? I want a MC to stop playing when I RELEASE the RIGHT arrow key. I tried some AS but it doesn't work. Do you need to add a listener or something? :confused:
Any help would be great! :o

Thx

Ruben
09-07-2005, 03:48 PM
How about this:// create a listener-object:
someListener = new Object();

// remember if the right-arrow key was last pressed or not:
someListener.onKeyDown = function () {
if (Key.isDown(Key.RIGHT)){
rightKeyPressed = true;
}else{
rightKeyPressed = false;
}
}

// if the right-arrow key was last pressed then stop the movieclip:
someListener.onKeyUp = function () {
if (rightKeyPressed){
myMovieClip.stop();
}
}

// add the listener to the key-object:
Key.addListener(someListener);

Here's some documentation on Key.onKeyUp (http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary411.html), Key.onKeyDown (http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary410.html) and the Key-object (http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary393.html).

:) - Ruben

smatmx
09-08-2005, 04:13 PM
Thanks, I'll try that.