Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Key Listener with MX to Switch Graphics

Status
Not open for further replies.

jjj4

Technical User
Joined
Aug 4, 2004
Messages
2
Location
CA
Hi,

I have a Flash animation of an old arcade cabinet.

While using the arrow keys on the keyboard I want my animation to show Left, Right, Up, Down and Normal states for each way you can move the joystick. I have pictures of the joystick for each direction.

I have created a movie clip with 5 frames(joystick_mc), each one with the different direction in its own frame. I put stop() in the 1st frame.

My code to make the switch happen is:

joystickListener = new Object();
joyStickListener.onKeyDown = function() {
if (Key.isDown(Key.LEFT)) {
joystick_mc.gotoAndPlay("left");
}
if (Key.isDown(Key.RIGHT)) {
joystick_mc.gotoAndPlay("right");
}
if (Key.isDown(Key.UP)) {
joystick_mc.gotoAndPlay("up");
}
if (Key.isDown(Key.DOWN)) {
joystick_mc.gotoAndPlay("down");
}
};
joyStickListener.onKeyUp = function() {
trace("re-centre joystick");
};
Key.addListener(joyStickListener);

My problem is nothing happens. I put trace("LEFT"); instead of joystick_mc.gotoAndPlay("left"); and it outputs fine, but trying to get it to play the frame "left" in my movie clip is not happening.

I have tried _root.joystick_mc.gotoAndPlay and _level0.joystick_mc.gotoAndPlay and nothing happens.

Can someone help me and let me know what I'm doing wrong.

Thank you for your time,
J
 
It's could be because you're continually sending 'gotoAnd Play('down')' etc. In other words the code is firing okay but you keep telling the movie to go to the same frame over and over so you're not seeing the animation play through.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top