flash actionscript:
Hi Scott,
Well, pausing your movie is a little tricky. The timeline keeps running
even if you issue a stop action, so you have to issue a stop to all of
your movie clips. In the example below, the only timeline that's stopped
is the root:
var myKeyListener:Object=new Object();
myKeyListener.onKeyDown=function() {
if (Key.getCode()==32) {
_root.stop();
}
}
Key.addListener(myKeyListener);
If you have any other movie clips running, you have to issue stop
actions to them as well.
Regards,
Patrick
[quoted text, click to view] Scott Sosebee wrote:
> I need to allow a user to pause an SWF by pressing the space bar, and the start
> it again by doing the same. I was told to use a "keylistener", but I am a
> BEGINNER to action scripting (much more of an animator). I have downloaded a
> script that lets me show dialogue when keys are pressed, but still cannot
> figure out the pause thing. If anyone could offer any help; I would really
> appreciate it.
>
> Best,
> Scott
I need to allow a user to pause an SWF by pressing the space bar, and the start
it again by doing the same. I was told to use a "keylistener", but I am a
BEGINNER to action scripting (much more of an animator). I have downloaded a
script that lets me show dialogue when keys are pressed, but still cannot
figure out the pause thing. If anyone could offer any help; I would really
appreciate it.
Best,
Scott
Thanks sooo much. I put an action into every movie and movie clip (the entire
swf runs in a "shell: load and unload movies). Regardless, it works great!
IHowever, I dont know why it works, but it does. Thanks again!
Scott
if you want one piece of code that will stop and start all moviecips you can
use:
myListener = new Object();
myListener.onKeyDown = function() {
if (Key.getCode() == Key.SPACE) {
if (!toggle) {
toggle = 1;
} else {
toggle = 0;
}
pauseF(_root,toggle);
}
};
pauseF(mc,param){
for(obj in mc){
if(typeof(mc[obj])=="moviecip"){
if(toggle){
mc[obj].stop();
} else {
mc[obj].play();
}
pauseF(mc[obj],param);
}
}
}
well, I spoke too soon.
The piece of code that was suggested to stop all movies returned this error:
**Error** Scene=Scene 1, layer=actions, frame=1:Line 8: Syntax error.
pauseF(mc,param){
Total ActionScript Errors: 1 Reported Errors: 1
the code below worked if I put it in every movie and movie clip, as well as in
the main "shell movie" in every frame where a new movie loads. However, it only
works if I view it in Flash. If I wief the movie in Flash Player (which is how
it will be viewd). The key actions are totally ignored. It also would sometimes
start the movie clip from tghe beginning instead of pausing. Any ideas?
Thanks again!
myListener = new Object();
myListener.onKeyDown = function() {
if (Key.getCode() == Key.SPACE) {
if (!toggle) {
stop();
toggle = 1;
} else {
play();
toggle = 0;
}
}
};
Key.addListener(myListener);
kglad;
I want to thank you in advance. I hope I'm not bugging you.
With that said, I'm not receiving a syntax error anymore, however, that piece
of code is yielding no results. it seems to be completely ignored. I put it in
my main "shell" movie as an action at the beginning of the timeline. I also
tried placing it in every action frame where a new movie is loaded. It still
did nothing.
Any ideas would be mucho appreciated.
best.
i had another typo using toggle instead of param in the body of pauseF().
also, that code won't control the _root timeline so i added code. and finally,
you don't want to put that code in a frame that's looped because you don't want
to continually define new listeners:
myListener = new Object();
myListener.onKeyDown = function() {
if (Key.getCode() == Key.SPACE) {
toggle = !toggle;
pauseF(_root, toggle);
}
};
function pauseF(mc, param) {
for (obj in mc) {
if (typeof (mc[obj]) == "movieclip") {
trace(mc[obj]);
if (param) {
_root.stop();
mc[obj].stop();
} else {
_root.play();
mc[obj].play();
}
pauseF(mc[obj], param);
}
}
}
Key.addListener(myListener);