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

Cannot get a button mouseover event to play a movie in Adobe Animate

Community Beginner ,
Apr 28, 2017 Apr 28, 2017

For some reason, the following code does not result in the Blue_Movie being played when I place the mouse over the Yellow_Button: 

var frequency = 3;

stage.enableMouseOver(frequency);

this.Yellow_Button.addEventListener("mouseover", fl_MouseOverHandler);

function fl_MouseOverHandler()

{

  this.Blue_Movie.play();

}

Anyone know why this would be?  This is code I made in a simple file I created to troubleshoot this issue in a project I am working on.  Nothing in the file except the button and the movie.

Thanks!

1.3K
Translate
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

Community Expert , Apr 30, 2017 Apr 30, 2017

try:

var frequency = 3;

stage.enableMouseOver(frequency);

this.Yellow_Button.addEventListener("mouseover", fl_MouseOverHandler.bind(this));

function fl_MouseOverHandler()

{

  this.Blue_Movie.play();

}

Translate
Community Expert ,
Apr 28, 2017 Apr 28, 2017

what's console.log() reveal?

Translate
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
Community Beginner ,
Apr 28, 2017 Apr 28, 2017

First off, thanks for responding!

Second, I should have mentioned that I am an ultra new-comer to Animate.  This is my first project.  So I am sorry to say that I don't know what console.log() means...?

Translate
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
Community Expert ,
Apr 28, 2017 Apr 28, 2017

it's the javascrpt equivalent of the actionscript trace() function.  ie, it lets you output text to a browser's debug console.

Translate
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
Community Beginner ,
Apr 30, 2017 Apr 30, 2017

Not sure what that means either, but that's my fault not yours.  I appreciate your help!

Translate
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 ,
Apr 29, 2017 Apr 29, 2017

Seems like we get this same question at least once a week.

In Canvas mode event handlers, "this" is set to the global window object, not the object that fired the event (as any reasonable person would assume). Basically the default value of this is useless, by design. There are a few workarounds for this problem.

You can use bind() on your event handler to force its this to a specific value.

Function.prototype.bind() - JavaScript | MDN

You can use on() instead of addEventListener(), which automatically applies bind().

EaselJS v0.8.2 API Documentation : EventDispatcher

You can use a global pointer to your object instead of using this.

You can use the .currentTarget property of the event object that's passed to event handler functions to reference the object that triggered the event handler.

EaselJS v0.8.2 API Documentation : Event

Translate
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
Community Beginner ,
Apr 30, 2017 Apr 30, 2017

Going to look this information over and try a few changes based it.  Will update.  Thank you for thorough response! 

Translate
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
Community Expert ,
Apr 30, 2017 Apr 30, 2017

try:

var frequency = 3;

stage.enableMouseOver(frequency);

this.Yellow_Button.addEventListener("mouseover", fl_MouseOverHandler.bind(this));

function fl_MouseOverHandler()

{

  this.Blue_Movie.play();

}

Translate
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
Community Beginner ,
May 05, 2017 May 05, 2017

Thank you.  Used this edit and it worked.

Translate
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
Community Expert ,
May 06, 2017 May 06, 2017
LATEST

you're welcome.

Translate
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
Community Beginner ,
May 05, 2017 May 05, 2017

Thank you!  And sorry for my late response here.  The first workaround you list (bind) did the trick.  I basically edited my code to look pretty much exactly like what kglad typed out below. 

Translate
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
Community Beginner ,
May 05, 2017 May 05, 2017

Would have marked this as correct answer but can only designate one as such, and the other answer displays the exact edit to my code that worked.  I feel if people are jammed up and browsing around needing the answer quickly they can zone right in on the bold part and make the quick change.  But this answer was indeed correct and very comprehensive in terms of the information you shared.  Thank you very much for helping.

Translate
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 ,
May 01, 2017 May 01, 2017

Also, if this button is an actual button, or there's a button anywhere else in the same project, you don't need this part, because Animate will add it automatically:

var frequency = 3;

stage.enableMouseOver(frequency);

Heck, even if you do need it, all you really need is this:

stage.enableMouseOver();

This enables mouseover at the default frequency, which is 20 times per second. Much more responsive than that sluggish 3 times per second.

Translate
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
Community Beginner ,
May 05, 2017 May 05, 2017

And thanks again!  I edited as you suggest here (removed frequency etc).

Translate
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