Copy link to clipboard
Copied
Hello i am a beginner at action script so this should be fairly easy to answer. Basically i want the default setting to stop the animation stop(); and then when space is held to play();
Here's what i have:
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyNotPressed);
function KeyPressed(evt:KeyboardEvent):void {
if (evt.keyCode==Keyboard.SPACE){
play();
}
}
function KeyNotPressed(evt:KeyboardEvent):void {
if (evt.keyCode!=Keyboard.SPACE){
stop();
}
}
Thanks for the help
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
var toggle:Boolean;
function KeyPressed(evt:KeyboardEvent):void {
if (evt.keyCode==Keyboard.SPACE){
if(toggle){
play();
} else {
stop();
}
toggle=!toggle;
}
}
Copy link to clipboard
Copied
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
var toggle:Boolean;
function KeyPressed(evt:KeyboardEvent):void {
if (evt.keyCode==Keyboard.SPACE){
if(toggle){
play();
} else {
stop();
}
toggle=!toggle;
}
}
Copy link to clipboard
Copied
Hi thanks very much, how would i make it start paused? Not that's its really needed but i would like when space is held instead of pressed.
Copy link to clipboard
Copied
to start paused:
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
var toggle:Boolean=true;
stop();
function KeyPressed(evt:KeyboardEvent):void {
if (evt.keyCode==Keyboard.SPACE){
if(toggle){
play();
} else {
stop();
}
toggle=!toggle;
}
}
Copy link to clipboard
Copied
Hi thanks very much. Do you know how to do when a key is held not pressed?
Copy link to clipboard
Copied
one way to do that would be to start a timer when a key is pressed and then use the timer listener to determine when and what action to take.
(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)
Copy link to clipboard
Copied
Why do i have to click first before doing it?
Copy link to clipboard
Copied
your swf needs focus to start. you can use code to do that,
stage.focus=this;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now