Skip to main content
Participating Frequently
June 2, 2022
Question

Animate cc canvas movie clip button.

  • June 2, 2022
  • 1 reply
  • 111 views

Hello everyone on the forum.
Maybe someone will guide me on how to solve this problem in adobe animate cc canwas.
In AS 3 the button works fine, but in javaScript I tried different ways and can't do it.

This is AS 3 code

var x:Boolean = false;

this.info_btn.addEventListener(MouseEvent.CLICK, onClick);
this.info_btn.addEventListener(Event.ENTER_FRAME, animate);

function onClick(e: MouseEvent):void {
if (x) {
x = true;
} else {
x = false;
my_mc.play();
}
}

function animate(e: Event): void {
if (!x && my_mc.currentFrame == my_mc.totalFrames - 46) {
my_mc.stop();

}
}


MovieClip starts from the current frame and stops at 47 frames from the end, and so on with each click.

 

below code but can't get it sorted

//var x = false;
//let x = false;
x = Boolean(false);


this.info_btn.addEventListener('click', onClick);

function onClick() {

if (x) {
x = true;
console.log('pause');

} else {
x = false;
root.my_mc.play();
console.log('happy');
}

}
If anyone guides me, thank you.

    This topic has been closed for replies.

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    June 2, 2022

    Hi.

     

    The code doesn't make much sense to me, but a possible solution would be:

    var root = this;
    var x = false;
    
    function onClick(e)
    {
    	if (x)
    		x = true;
    	else
    	{
    		x = false;
    		root.my_mc.play();
    	}
    }
    
    function animate(e)
    {
    	if (!x && root.my_mc.currentFrame === root.my_mc.totalFrames - 46)
    		root.my_mc.stop();
    }
    
    root.info_btn.addEventListener("click", onClick);
    createjs.Ticker.addEventListener("tick", animate);

     

    I hope it helps.

     

    Regards,

    JC

    Participating Frequently
    June 8, 2022

    Hello

    Thank you for your reply.

    This is my first time on this forum.

    Let me write something about myself briefly.

    Writes through google translator, I think you will understand something of this.

    My name is Jan, this year I will be 62 years old, I started on the pro versions of Flash,
    I learn from flash literature, ActionScript 3.0 online courses.
    But Animate CC canvas is difficult and it takes time, when I retire I will devote myself to it, I'm very interested in computer animation.

    I did a project with AS 3 360 ° photos once and I would like to transfer it to canvas.
    The code you wrote to me works, but other buttons take over its function, it must be a local variable, I have to work on it, or ask on the forum.

    Thanks again for your answer and I think we will exchange a few more sentences in the forum.
    It was nice to meet you.

    I am sending greeting and I wish you good luck.

    Jan