all groups > flash actionscript > july 2004 >
You're in the

flash actionscript

group:

Movieclips and isDown


Movieclips and isDown 9toes
7/29/2004 11:40:16 PM
flash actionscript: im try to make this movie clip that stops at the 1st frame but once you press
ENTER button it goes to the 2nd frame and is you press ENTER again it goes back
to first frame. the codes the exact same for 2nd frame except that i changed
nextFrame to prevFrame. if the action script is totaly wrong can you post a
script that would work.



if (Key.isDown(Key.ENTER)) {
nextFrame();
}
Re: Movieclips and isDown mandingo
7/30/2004 12:15:49 AM
The trouble with that is that it executes when the frame loads... and at that
point no keys are down so nothing will happen... what you need is something to
'listen' for the key press... a Key Listener...

if(typeof(myKeyListener) == "undefined"){
myKeyListener = new Object();
myKeyListener.onKeyDown = function() {
if (Key.isDown(Key.ENTER)) {
if (_currentframe == 1) {
nextFrame();
return;
}
if (_currentframe == 2) {
prevFrame();
return;
}
}
};
Key.addListener(myKeyListener);
}
stop();

The reason I added the condition at the start is to prevent duplicate objects
being created every time it returns to frame 1...

P.S. The ENTER Key will not work correctly in the Flash author/test
environment... it is a shortcut key for advancing the playhead... it will work
in a compiled SWF though.

I hope that helps,
cheers,
AddThis Social Bookmark Button