Help with Keyboard actions

Hi guys, im having a headache time trying to work out how this would work.
Ive got a movie clip with the variable “_root.bla.bla”(frame 1 is stopped while the rest of the frame doesnt stop in this movie clip). I want to add a actionscript that when i hold onto a keyboard button like up arrow, it will start playing from frame 2 onwards and when i let go of it, it will stop playing and immediately return to frame 1.

Can anyone please enlighten me on this?

//define onKeyDown event handler
this.onKeyDown = function() {
	//if the up arrow is pressed
	if (Key.isDown(Key.UP)) {
		//play
		this.play();
	}
};
//define onKeyUp event handler
this.onKeyUp = function() {
	//if the up arrow is not pressed
	if (!Key.isDown(Key.UP)) {
		//send playhead to frame 1 and stop
		this.gotoAndStop(1);
	}
};
//register object as listener for the Key object
Key.addListener(this);

hey awesome dude that worked great, thanks a lot.
Oh and BTW, there should be a onClipEvent (enterFrame) bracketed on the code, but anyway the code rocks

No problem. :slight_smile:

And no, you don’t need to put the code within an [font=courier new]enterFrame[/font] event, the code was supposed to be on the frame actions rather than the symbol actions; but if you want to put it on the symbol actions, use the [font=courier new]load[/font] event instead. :wink:

onClipEvent (load) {
	this.onKeyDown = function() {
		if (Key.isDown(Key.UP)) {
			this.play();
		}
	};
	this.onKeyUp = function() {
		if (!Key.isDown(Key.UP)) {
			this.gotoAndStop(1);
		}
	};
	Key.addListener(this);
}