I’m trying to make something where if the viewer holds in an arrow key on their keyboard, it will make a movie clip move across the screen with the AS for it to go to the next frame when the key is pressed. When the arrow key is released, is there any way I could activate an action at that time?
Here I think I see what you’re trying to accomplish:
onClipEvent (load) {
keyList = new Object();
Key.addListener(keyList);
}
onClipEvent (onKeyDown) {
delete onEnterFrame;
if (keyList.getCode == Key.LEFT) {
_x -= 5;
}
//...and yada yada yada, i hope you get the picture
}
onClipEvent (onKeyUp) {
this.onEnterFrame = function () {
//insert your usual enterFrame code here
}
}
Now, I haven’t tested this code, so it may or may not work. What it basically does is moves when you press the arrow keys (assuming you were able to add the extra code for right, up, and down), and when you release the key, it will assign the onEnterFrame function.
I’m a little confused… This was my original script…
onClipEvent (enterFrame) {
if(Key.isDown(Key.LEFT)){
_x=_x-5;
tellTarget (_root.char) {
nextFrame();
}
}
}
I think i figured how to put it all togeather, but as you said the code may be wrong. Heres the output.
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 5: Invalid movie clip event specified.
onClipEvent (onKeyDown) {
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 12: Invalid movie clip event specified.
onClipEvent (onKeyUp) {
Whoops, those are invalid movie clip events. (those debug windows have yet to fail me :)). Here’s the fixed code:
onClipEvent (load) {
keyList = new Object();
Key.addListener(keyList);
}
onClipEvent (keyDown) {
delete onEnterFrame;
if (keyList.getCode == Key.LEFT) {
_x -= 5;
}
//...and yada yada yada, i hope you get the picture
}
onClipEvent (keyUp) {
this.onEnterFrame = function () {
//insert your usual enterFrame code here
}
}
Well, thats fixed now, but theres another problem :-. The keyDown script isn’t activating…
Just keeping the thread alive… :-\
Can you be more specif on what u are trying to do?
Trying to learn how it would be possibal for me to make a side scrolling game. (Right now, I have a stick figure that stands in place, then when an arrow key is held in I want it to begin moving and have the movement animation, which is what the whole nextFrame thing is for (That part works).) But right now, I’m having troubles with this script. I tried modifying a bit, but it didn’t really fix it much. The main problem is telling the movie clip to go to a certain frame when the button is released.
OOH! I figured it out myself!! (-: Thats a first…