简体   繁体   中英

Animate CC - if Else statements

I am currently trying to get a grasp of Adobe Animate CC, and how if Else -statement can be used with the tool. In this case, I would like to create a play/pause button. I could probably achieve this with JavaScript, but Animate CC doesn't tell me what are the ID's of the elements I create.

Right now, I have created an animation which plays automatically and loops, and with the button-click the animation stops. What I would like to also achieve is, that 2nd click to the button would replay the animation . Here is the code, maybe someone can help me to achieve this?

 this.Play_btn.addEventListener("click",playAnimation.bind(this)); function playAnimation() { this.stop(); }

To answer the question: "How can an If-Else statement be used to pause/rewind a clip?" then you would first need a condition to verify whether the "paused" property is true or false. Once you know that you will know whether to play the clip from the beginning, or pause it.

function playAnimation() {
    if (this.paused) {
        this.gotoAndPlay(0);
    } else {
        this.stop();
    }
}

As for "How do I access my graphic IDs?" You set IDs when you give the MovieClip its instance name. If the current timeline has an object called Play_btn , then this.Play_btn refers to the object as long as the script knows what this means. You can also use this["Play_btn"] if you need to access it programmatically.

The .bind(this) statement allows this and this.Play_btn to work inside playAnimation the same way they would outside playAnimation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM