Skip to main content
Participant
August 6, 2020
Question

Trying to get the animation to play only though the play button.

  • August 6, 2020
  • 1 reply
  • 175 views

I don't understand actions all too well. I'm trying to get my animation to play only when "play" is pressed, the whole thing plays by itself instead.

    This topic has been closed for replies.

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    August 7, 2020

    Hi.

     

    You need to first stop the timeline you're trying to control and then add an event listener to a button to play the same timeline.

     

    Here are code suggestions for both HTML5 Canvas and AS3 documents:

     

    HTML5 canvas

    var root = this;
    
    root.start = function()
    {
    	root.gotoAndPlay(1);
    };
    
    if (!root.started)
    {
    	root.stop();
    	root.yourPlayButton.on("click", root.start);
    	root.started = true;
    }

     

    AS3

    import flash.events.MouseEvent;
    
    function start(e:MouseEvent):void
    {
    	gotoAndPlay(2);
    }
    
    stop();
    yourPlayButton.addEventListener(MouseEvent.CLICK, start);

     

    Regards,

    JC