View Full Version : How Do U Make An Mc Stay on Button Down???
JoRdAnMaN
July 13th, 2006, 09:57 PM
Im trying to make a button that when u hold down say key D a mc goes to a certain frame and stays untill the key D is released. Thanks!
StarXploser
July 14th, 2006, 09:42 AM
use onPress instead of onRelease ?
I dont really understand the question.
What is it doing right now ?
540media
July 14th, 2006, 11:39 AM
I'd use Key.isDown
if (Key.isDown(key number)) {
mc.gotoAndPlay (frame number);
} else {
mc.gotoAndStop(frame number);
}
is that the kinda thing you mean??
StarXploser
July 14th, 2006, 11:41 AM
you've gotta love those 2 lines questions. I have no idea what he's talking about :)
JoRdAnMaN
July 14th, 2006, 02:26 PM
Sry i wasnt clearer, i want to be able to have a button where if you are holding down the A key MC2 goes to frame 2, and when you release the key A it goes back to frame 1.
StarXploser
July 14th, 2006, 02:32 PM
myBtn.onPress=function()
{
gotoAndStop(2);
}
myBtn.onRelease=function()
{
gotoAndStop(1);
}
JoRdAnMaN
July 14th, 2006, 02:51 PM
myBtn.onPress=function()
{
gotoAndStop(2);
}
myBtn.onRelease=function()
{
gotoAndStop(1);
}
Where do i put this? On the button that is pressed by hitting the key A? Im confused by this script
REEFˇ
July 14th, 2006, 03:00 PM
According to that code, I'd think you'd put it on a frame. But I'm not sure how that code detects the "A" key at all.
StarXploser
July 14th, 2006, 03:20 PM
oups i'm sorry, i forgot that it was a key thing not a button
let me change the code.. oh crap, i need to go. i'll be back in an hour. Maybe reef can put some onKeyDown stuff in there to make it work for you. I'll help you when i get back otherwise.
REEFˇ
July 14th, 2006, 03:34 PM
Actually onKeyDown doesnt exactly work for letter keys. I can help out with half the code, but besides that, I can't tell you how to detect a key release.
// Code on frame:
onEnterFrame = function () {
pressedKey = Key.getAscii();
// Detects lower case or upper case "a/A".
if (pressedKey == 65 || pressedKey == 97) {
// Replace mc2instance name with MC2s instance name.
mc2instancename.gotoAndStop(2);
}
};
Er, now you just need a code to detect when the "a/A" key is released. Lol.
StarXploser
July 14th, 2006, 04:03 PM
i meant something like that:
Key.addListener(_root);
_root.onKeyDown = function () {
pressedKey = Key.getAscii();
// Detects lower case or upper case "a/A".
if (pressedKey == 65 || pressedKey == 97) {
mc2instancename.gotoAndStop(2);
}
};
_root.onKeyUp = function () {
mc2instancename.gotoAndStop(1);
};
the onKeyUp is a little weird and doesnt really work the way it should because it doesnt really know what key was pressed before.. but it works fine for now... kinda depends on what he wants to do w/ it
JoRdAnMaN
July 14th, 2006, 04:26 PM
i meant something like that:
Key.addListener(_root);
_root.onKeyDown = function () {
pressedKey = Key.getAscii();
// Detects lower case or upper case "a/A".
if (pressedKey == 65 || pressedKey == 97) {
mc2instancename.gotoAndStop(2);
}
};
_root.onKeyUp = function () {
mc2instancename.gotoAndStop(1);
};
Thx a lot it works great, but how would i change the key instead of a/A to d/D?
REEFˇ
July 14th, 2006, 04:31 PM
Get the ascii code for lowercase and upper case d.
Type in: trace(ord('d') + "," + ord('D')); and you'll get 2 ascii codes you can replace the 65/97 with.
StarXploser
July 14th, 2006, 04:37 PM
omg it's almost your 8000th post :)
REEFˇ
July 14th, 2006, 05:36 PM
lol yay :dog:
JoRdAnMaN
July 14th, 2006, 10:12 PM
Aw damn i went n put it into my game and now i see how that works now with the release. It messes up my game to much, is there any way so it is just so that when d is released?
StarXploser
July 14th, 2006, 10:49 PM
well.. if you go to frame 2 when d is release then how do oyu get to frame1
JoRdAnMaN
July 15th, 2006, 01:47 PM
well.. if you go to frame 2 when d is release then how do oyu get to frame1
I still mean when D is pressed it should go to frame 2, just i was wondering if its possible to make it so when only key D is released that it goes back to frame 1, instead of just releasing any key.
StarXploser
July 15th, 2006, 02:04 PM
_global.lastkey = "";
Key.addListener(_root);
_root.onKeyDown = function () {
pressedKey = Key.getAscii();
_global.lastkey = pressedKey
// Detects lower case or upper case "a/A".
if (pressedKey == 65 || pressedKey == 97) {
mc2instancename.gotoAndStop(2);
}
};
_root.onKeyUp = function () {
if (pressedKey == 65 || pressedKey == 97) {
mc2instancename.gotoAndStop(1);
}
};
JoRdAnMaN
July 15th, 2006, 05:49 PM
Ty so much it works perfect!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.