Skip to main content
Participant
December 11, 2020
Question

Smooth action

  • December 11, 2020
  • 1 reply
  • 298 views

Hi there, my programmer has added a Yes/No slider item to a project but I think its action could be smoother as it switches from the Yes/No state. See attached MP4
Is there a way to do this?

Cheers, Graham

 

 

    This topic has been closed for replies.

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    December 11, 2020

    Hi.

     

    There is.

     

    Please check out this example:

    adobe/animate cc/html5_canvas/switch_button at master · joao-cesar/adobe (github.com)

     

    The code / JS to create the button interactivity is the following (placed in the main timeline):

    this.makeSwitchButton = function(target, onLabel, offLabel)
    {
    	if (!target.started)
    	{
    		target.stop();
    		target.toggled = false;
    		
    		target.hit.on("click", function(e)
    		{
    			e.currentTarget.parent.toggled = !e.currentTarget.parent.toggled;
    			e.currentTarget.parent.gotoAndPlay(e.currentTarget.parent.toggled ? onLabel : offLabel);
    		});
    		
    		target.started = true;
    	}
    };

     

    Then place this code inside the Movie Clip instance being used as a button:

    exportRoot.makeSwitchButton(this, "yes", "no");

     

    I hope this helps.

     

    Regards,

    JC

    Participant
    December 11, 2020

    Thank you JC, I will pass this onto our programmer - I'm sure it will help!

    Cheers, Graham

    JoãoCésar17023019
    Community Expert
    Community Expert
    December 11, 2020

    You're welcome!

     

    Please let us know if you need further help.

     

    Regards,

    JC