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

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

New Here ,
Aug 28, 2024 Aug 28, 2024

Copy link to clipboard

Copied

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.

TOPICS
ActionScript , Code , Error

Views

99

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

Community Expert , Aug 28, 2024 Aug 28, 2024

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

Votes

Translate

Translate
Community Expert ,
Aug 28, 2024 Aug 28, 2024

Copy link to clipboard

Copied

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

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
New Here ,
Aug 28, 2024 Aug 28, 2024

Copy link to clipboard

Copied

Thank you very much.

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
Community Expert ,
Aug 28, 2024 Aug 28, 2024

Copy link to clipboard

Copied

LATEST

You're welcome.

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