Skip to main content
Henri v
Participant
Aug 28, 2024 7:58 AM UTC
Answered

Problem: Button - GotoAndStop - addEventListener - didn't work

Hello everyone,

I cannot solve the following problem and cannot find the error.

 

I used the exercise file from the ‘Adobe’ tutorial as a template. https://creativecloud.adobe.com/cc/learn/animate/web/animated-infographic?locale=en

 

This file can be tested from ‘Animate’ and the two buttons work. If I rebuild this file and use the same code, the control of the ‘Movieclip’ with the gotoAndStop command is not activated.
The code from the example file:

 

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

function fl_MouseClickHandler_2()
{
	this.popup_energy.play();
}

this.info_network.addEventListener("click", fl_MouseClickHandler_1.bind(this));

function fl_MouseClickHandler_1()
{

this.popup_network.play();

}

 

The code from me:

 

var localThis = this;

function init() {
this.taste01.addEventListener("click", Mausklick_Taste01(this));
}

function Mausklick_Taste01()
{
	this.display1.gotoAndStop(1);
}

init();

 

I have a movieclip with the instance name ‘display1’. No matter what I have tried so far, the ‘gotoAndStop’ command is not triggered. In the Andobe example file it works as a preview, locally in the browser and on a server.

I have already searched the forum and tried everything possible.
- I have packed the whole code into an init function.
- used this with a variable
- exchanged the image number with a jump label

I can't find the basic difference to the Adobe example file. This file even works locally as an html file, with mine the button function does not even work locally but only from a server.

The two .fla files are here: https://hidrive.ionos.com/share/23zdm2gg3j 

I would appreciate an answer.

This topic is closed to new replies. Start a new post to keep the conversation going.
JoãoCésar17023019
JoãoCésar17023019Correct answer
Community Expert
Aug 28, 2024 12:30 PM UTC

Hi.

 

You have problems on handling context (the this keyword) and on passing the event handler function. Your code should be something like this:

var localThis = this;

function init()
{
	localThis.taste01.addEventListener("click", Mausklick_Taste01);
}

function Mausklick_Taste01()
{
	localThis.display1.gotoAndStop(1);
}

init();


Regards,
JC

3 replies

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
Aug 28, 2024 12:30 PM UTC

Hi.

 

You have problems on handling context (the this keyword) and on passing the event handler function. Your code should be something like this:

var localThis = this;

function init()
{
	localThis.taste01.addEventListener("click", Mausklick_Taste01);
}

function Mausklick_Taste01()
{
	localThis.display1.gotoAndStop(1);
}

init();


Regards,
JC

Translate
Henri v
Henri vAuthor
Participant
Aug 28, 2024 2:48 PM UTC

Thank you very much.

Translate
JoãoCésar17023019
Community Expert
Community Expert
Aug 28, 2024 2:50 PM UTC

You're welcome.

Translate