Skip to main content
Participant
March 27, 2019
Answered

Can't play multiple Movie Clips on same frame

  • March 27, 2019
  • 1 reply
  • 262 views

Hello,

I'm in the process of creating an interactive story using HTML 5 Canvas and have encountered an issue when using multiple Movie Clips on the same frame. The gist of my project is each scene is on one frame and all the animation is embedded into Movie Clips. The issue occurs when trying to add interactivity to the movie clips, the user clicks something and that symbol does an animation. At the moment only the last function will work no matter which function it is.

Here's my code;

this.stop(); //stops at this frame

this.midWave.addEventListener("click", fl_MouseClickHandler_2.bind(this));

function fl_MouseClickHandler_2()

{

this.Fish2.play();

}

this.Ship1.addEventListener("click", fl_MouseClickHandler_2.bind(this));

function fl_MouseClickHandler_2()

{

this.Ship1.play();

}

this.frontWave.addEventListener("click", fl_MouseClickHandler_2.bind(this));

function fl_MouseClickHandler_2()

{

this.Fish1.play();

}

Thanks in advance for reading!

Message was edited by: João César de Lima | Reason: font size too small

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

This is happening because you're redeclaring the fl_MouseClickHandler_2 function over and over again.

function fl_MouseClickHandler_2()

{

    this.Fish2.play();

}

function fl_MouseClickHandler_2()

{

    this.Ship1.play();

}

function fl_MouseClickHandler_2()

{

    this.Fish1.play();

}

Assign different names as you want different codes to run.

Regards,

JC

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
March 27, 2019

Hi.

This is happening because you're redeclaring the fl_MouseClickHandler_2 function over and over again.

function fl_MouseClickHandler_2()

{

    this.Fish2.play();

}

function fl_MouseClickHandler_2()

{

    this.Ship1.play();

}

function fl_MouseClickHandler_2()

{

    this.Fish1.play();

}

Assign different names as you want different codes to run.

Regards,

JC

Legend
March 27, 2019

Or, better, just put all the movieclip actions in a single event handler.