Skip to main content
Sacha De Faria
Participating Frequently
January 5, 2023
Answered

prevent a click on a button while another animation is running

  • January 5, 2023
  • 4 replies
  • 462 views

Hello everyone,
I have created a map with a "outbound" button and a "return" button.
When I click on the "outbound trip" button, it launches an animation on the map that I have integrated in a symbol outside the map of a boat going from point A to point B.

My problem is that I can't figure out how to prevent clicking on the return path while the outbound path animation is active, because the return animation should not be triggered until the outbound path is completed, but the two should be separate.

Can you help me? I'm a beginner in code and I've been stuck for more than a week.

Thanks in advance

Translated with www.DeepL.com/Translator (free version)

    This topic has been closed for replies.
    Correct answer kglad

    Hi kglad, thank for your help and answer 🙂

    For my first problem described above, yes I thank you, but now I want to be able to stop and start my sequence with a button. To do this I created a button symbol in my library, then I imported it into my symbol where there is my sequence (a path from a point A to a point B over a specified time in the timeline). So that it appears only when my sequence is launched I put an empty keyframe in frame 1 and in the last frame as in my sequence, which makes the object appears only during the playback of the sequence and then disappears.
    I spent the evening yesterday trying to find how to do it with tutorials on the internet but I got a lot of error messages.
    This morning it works perfectly that is to say that the play/pause button appears well when I launch my sequence by clicking on the button of the scene where it is and it disappears well at the end of the playback of my sequence, I can click on it but the code does not work and the sequence does not stop, on the other hand there is no more error the code used is a code found on a tutorial, if someone knows how to adapt it so that it works I'm a taker
    code : if (!thisplayPauseBtn.hasEventListener("click")) {
    this.playPauseBtn.addEventListener("click",maFct21.bind(this));
    }
    function maFct21 () {
    this.paused=!this.paused;
    }


    for others, there should be dot between this and playPauseBtn

     

     if (!thisplayPauseBtn.hasEventListener("click")) {
    this.playPauseBtn.addEventListener("click",maFct21.bind(this));
    }
    function maFct21 () {
    this.paused=!this.paused;
    }

    4 replies

    Sacha De Faria
    Participating Frequently
    January 16, 2023

    Thank you for all your answers, the problem is that I am really bad in Javascript and in coding in general I do not understand the terms you use (roots etc. it is necessary to vulgarize as if you were speaking to a child because I do not master Javascript at all)
    I found a solution thank à coworker

    italics = buttons

    bold = functions

     

    ///////////////VARIABLES

    this.stop();

    _this = this;

    /*that's to say that a clip can have the behavior of a button*/

    stage.enableMouseOver();

     

     

    //////////PROGRAMME

     

    /*This is so that when you pass the mouse pointer over it it turns into a hand*/

    _this.btn_rtr1.cursor = "pointer";

    _this.btn_retourS2_1.cursor = "pointer";

    _this.btn_trajAller_1.cursor = "pointer";

     

    /*backspace button*/

    if(!_this.btn_rtr1.hasEventListener("click", maFct5)){

                    _this.btn_rtr1.addEventListener("click", maFct5);

    }

     

     

     

    /* return trip button*/

    if(!_this.btn_retourS2_1.hasEventListener ("click", maFct7)){

                                   _this.btn_retourS2_1.addEventListener ("click", maFct7);

    }

     

     

    /* outbound button*/

    if(!_this.btn_trajAller_1.hasEventListener("click", maFct6)){

                                   _this.btn_trajAller_1.addEventListener("click", maFct6);

    }

     

     

    ///////////FUNCTIONS

     

    function maFct5(e){

                    _this.gotoAndStop(1);

    }

     

    /*

    This function allows you to launch the symbol of the clip that contains the timeline

    the second occurrence of the button of the other path blocks the other button

    until the ride is complete, using play instead of GotoandPlay

    avoid the spamclick

    */

     

    function maFct6(e){

                    if(_this.btn_allerS2_1.currentFrame == 0 && _this.btn_trajretourS2_1.paused)

                    {

                                   _this.btn_allerS2_1.play();

                    }

    }

    /*

    This function allows you to launch the symbol of the clip that contains the timeline

    the second occurrence of the button of the other path blocks the other button

    until the ride is complete, using play instead of GotoandPlay

    avoid the spamclick

    */

     

    function maFct7(e){

                    if(_this.btn_trajretourS2_1.currentFrame == 0 && _this.btn_allerS2_1.paused)

                    {

                                   _this.btn_trajretourS2_1.play();

                    }

    }

     

    }

    kglad
    Community Expert
    Community Expert
    January 16, 2023

    @Sacha De Faria 

     

    does it work the way you want?

    Sacha De Faria
    Participating Frequently
    January 17, 2023

    Hi kglad, thank for your help and answer 🙂

    For my first problem described above, yes I thank you, but now I want to be able to stop and start my sequence with a button. To do this I created a button symbol in my library, then I imported it into my symbol where there is my sequence (a path from a point A to a point B over a specified time in the timeline). So that it appears only when my sequence is launched I put an empty keyframe in frame 1 and in the last frame as in my sequence, which makes the object appears only during the playback of the sequence and then disappears.
    I spent the evening yesterday trying to find how to do it with tutorials on the internet but I got a lot of error messages.
    This morning it works perfectly that is to say that the play/pause button appears well when I launch my sequence by clicking on the button of the scene where it is and it disappears well at the end of the playback of my sequence, I can click on it but the code does not work and the sequence does not stop, on the other hand there is no more error the code used is a code found on a tutorial, if someone knows how to adapt it so that it works I'm a taker
    code : if (!thisplayPauseBtn.hasEventListener("click")) {
    this.playPauseBtn.addEventListener("click",maFct21.bind(this));
    }
    function maFct21 () {
    this.paused=!this.paused;
    }

    Community Expert
    January 6, 2023

    Sometimes what I do is have a symbol that goes over the button with the opacity turned down so the button is untouchable until the animation is complete. You wouldn't even have to code it. Just add it to come in when the animation starts and then when the animation is done just have it go away and the button will be active again. you can do that in the animation timeline. 

    kglad
    Community Expert
    Community Expert
    January 5, 2023

    p.s. you should also alter the alpha (eg, 0.3) of any button that's disabled to inform the user.

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 5, 2023

    Hi.

     

    If I understand correctly, you should set the mouseEnabled property of the button that should not be clicked to false as soon as the user clicks in the animation button and then place an instruction in last frame of the animation to reactivate the button (e.g.: this.parent.yourButton.mouseEnabled = true;  or exportRoot.yourButton.mouseEnabled = true;).

     

    You can also share a screenshot or even your code so that we can understand better.

     

    Regards,

    JC