开发者

Need to cancel an actionscript command stop() and continue my project

开发者 https://www.devze.com 2023-02-05 06:22 出处:网络
I have an Actionscript on an invisible button in m开发者_如何学编程y Flash project and it is supposed to stop on a frame if it is clicked. This is the script on the button:

I have an Actionscript on an invisible button in m开发者_如何学编程y Flash project and it is supposed to stop on a frame if it is clicked. This is the script on the button:

invisobutton.addEventListener(MouseEvent.CLICK,stopframe);
function stopframe(Event:MouseEvent):void{
stop();
}

with invisobutton being the instance name of the button. It works if you click anywhere inside the invisible button the movie stops on that frame. My problem is that I do not know how to cancel the stop and continue where the movie paused. Is there a counter for the stop() command so that it can be like off and there was an on switch? I thought about using a second function for go to and play like this:

invisobutton.addEventListener(MouseEvent.MOUSE_OUT, restart);
                              function restart(Event:MouseEvent):void{
gotoAndPlay(*);

but I am not sure how to know what to put into the (*) so that it plays from right where it was stopped.

If someone could please advise me if there is a reverse command to stop() that can turn it off ans start again. I already tried play() but I got errors from Flash over it. I thought about start() but I had never heard of or seen such a command. Or if someone could tell me a way to correctly retrieve the frame number when the stop() command executes.


Assuming that what you want is to use the same button to toggle between play and stop, you can use the following code:

var lastFrame:int;
var isPlaying:Boolean = true;

invisobutton.addEventListener(MouseEvent.CLICK, toggleFrame);

function toggleFrame(Event:MouseEvent):void { 
    if ( isPlaying ) {
        lastFrame = this.currentFrame;
        stop();         
    } else {
        this.gotoAndPlay( lastFrame );
    }

    isPlaying = ! isPlaying;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消