Skip to main content
Participant
August 7, 2019
Answered

HTML5 canvas looping animation using code

  • August 7, 2019
  • 2 replies
  • 1180 views

Hi!

I'm new to animate html5! I have some prior experience coding with Action Script but it's been a few years so I'm pretty rusty.

If anyone has any beginner tutorials they could point me toward that would be awesome!

Now to my question: I have a movie clip that I'm bringing onto the stage with 'addChild' and another movie clip in there with a timeline. I'm wondering how to control the nested movie clip and loop it at a certain point? This is the code I've got so far. I just can't seem to get the if statement to work

var Cover = new lib.cover_mc();

createjs.Ticker.on("tick", animLoop);

this.addCover = function () {

this.addChild(Cover);

}

this.addCover();

function animLoop(e) {

if (Cover.bee_mc.currentFrame("endLoop")) {

Cover.bee_mc.gotoAndPlay("startLoop");

}

}

    This topic has been closed for replies.
    Correct answer caitlinm58911893

    actually I figured it out! I wanted the animation in a nested movie clip to loop when it reached a particular frame in the timeline (so I could trigger some other animation in the same timeline with a mouse click). This is the resulting code:

    createjs.Ticker.on("tick", loopAnim);

    function loopAnim(e) {

    if (Cover.bee_mc.currentLabel == "endLoop") {

    Cover.bee_mc.gotoAndPlay("startLoop");

    }

    }

    2 replies

    caitlinm58911893AuthorCorrect answer
    Participant
    August 7, 2019

    actually I figured it out! I wanted the animation in a nested movie clip to loop when it reached a particular frame in the timeline (so I could trigger some other animation in the same timeline with a mouse click). This is the resulting code:

    createjs.Ticker.on("tick", loopAnim);

    function loopAnim(e) {

    if (Cover.bee_mc.currentLabel == "endLoop") {

    Cover.bee_mc.gotoAndPlay("startLoop");

    }

    }

    Legend
    August 7, 2019

    Please explain what you think the currentFrame() function does, so we can know what you're trying to do.

    Participant
    August 7, 2019

    I think it gets current frame of a movie clip?

    That's obviously wrong, but how else do I access a particular frame or frame label of a movie clip?