• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Trouble making an HTML5 pulldown menu in Animate

Contributor ,
Jun 12, 2019 Jun 12, 2019

Copy link to clipboard

Copied

I have a button over an image and I want to make a pulldown menu pop up when someone hovers their mouse over it, but it's not working. I'm publishing to HTML5. javascript console in Safari says "TypeError: undefined is not an object (evaluating 'this.movieClip_1.play')". the alert fires, however. In movieClip_1 i have "this.stop();" on the first frame and the frame where the pulldown menu is visible.

var frequency = 3;

stage.enableMouseOver(frequency);

this.movieClip_1.addEventListener("mouseover", fl_MouseOverHandler_3);

function fl_MouseOverHandler_3()

{

   alert("Moused over");

  this.movieClip_1.play();

}

Views

298

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Jun 12, 2019 Jun 12, 2019

Hi,

try this code (I've highlighted what I added/changed)...

var frequency = 3;

var _this = this;

stage.enableMouseOver(frequency);

this.movieClip_1.addEventListener("mouseover", fl_MouseOverHandler_3);

function fl_MouseOverHandler_3()

{

  alert("Moused over");

  _this.movieClip_1.play();

}

Hope that helps?

Cheers

Greg

Votes

Translate

Translate
Engaged ,
Jun 12, 2019 Jun 12, 2019

Copy link to clipboard

Copied

Hi,

try this code (I've highlighted what I added/changed)...

var frequency = 3;

var _this = this;

stage.enableMouseOver(frequency);

this.movieClip_1.addEventListener("mouseover", fl_MouseOverHandler_3);

function fl_MouseOverHandler_3()

{

  alert("Moused over");

  _this.movieClip_1.play();

}

Hope that helps?

Cheers

Greg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 12, 2019 Jun 12, 2019

Copy link to clipboard

Copied

LATEST

You're having trouble because, by default, "this" in CreateJS event handlers points to the global document context instead of the context of the object that triggered the event. This was a terrible design decision, but we're stuck with it now.

You can work around it by either declaring a local alias to the desired context, as Greg does above, or by using bind() to force the event handler function to execute in the desired context.

In this case, since you're controlling the same object as has the event listener, there's also a third option. You can use evt.currentTarget. E.g.--

function fl_MouseOverHandler(evt) {

     evt.currentTarget.play();

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines