Highlighted

Trouble making an HTML5 pulldown menu in Animate

Contributor ,
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();

}

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

TOPICS
Discussions

Views

168

Likes

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

Trouble making an HTML5 pulldown menu in Animate

Contributor ,
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();

}

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

TOPICS
Discussions

Views

169

Likes

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
Jun 12, 2019 0
Engaged ,
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

Likes

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
Reply
Loading...
Jun 12, 2019 0
ClayUUID LATEST
Adobe Community Professional ,
Jun 12, 2019

Copy link to clipboard

Copied

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();

}

Likes

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
Reply
Loading...
Jun 12, 2019 2