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

Canvas project - Target a movieclip from a nested function problem

Explorer ,
Mar 22, 2022 Mar 22, 2022

Copy link to clipboard

Copied

I cant seem to target a movieclip from a nested function it works fine from a function "ArgentinaBtn" that's called onClick... but cant target it if I place a function "defaultFade"within the function"ArgentinaBtn". Please anyhelp 🙂

function defaultFade() {
	//alert("defaultFade worked!")
	this.page_map.interactive_map.Argentina.alpha = 0.5;
	this.page_map.interactive_map.Australia.alpha = 0.5;
	this.page_map.interactive_map.Austria.alpha = 0.5;
}

this.page_map.interactive_map.Argentina.addEventListener("click", ArgentinaBtn.bind(this));

function ArgentinaBtn()
{
	//this.page_map.interactive_map.Argentina.alpha = 0.5;
	//this.page_map.interactive_map.Australia.alpha = 0.5;
	//this.page_map.interactive_map.Austria.alpha = 0.5;
	defaultFade();
	
	//overwrite
	this.page_map.interactive_map.Argentina.alpha = 1;
}

Views

216

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 , Mar 22, 2022 Mar 22, 2022

Hi.

 

The context of the defaultFade function is not the main timeline but rather the window object. You need to bind the defautFade function to the main timeline.

 

One way of doing this in your code is to replace the call:

defaultFade();

By:

defaultFade.call(this);

 

But I think it's easier in most cases to store a reference to the main timeline in a variable. Like this:

var root = this;

function defaultFade()
{
	root.page_map.interactive_map.Argentina.alpha = 0.5;
	root.page_map.interactive_
...

Votes

Translate

Translate
Community Expert ,
Mar 22, 2022 Mar 22, 2022

Copy link to clipboard

Copied

Hi.

 

The context of the defaultFade function is not the main timeline but rather the window object. You need to bind the defautFade function to the main timeline.

 

One way of doing this in your code is to replace the call:

defaultFade();

By:

defaultFade.call(this);

 

But I think it's easier in most cases to store a reference to the main timeline in a variable. Like this:

var root = this;

function defaultFade()
{
	root.page_map.interactive_map.Argentina.alpha = 0.5;
	root.page_map.interactive_map.Australia.alpha = 0.5;
	root.page_map.interactive_map.Austria.alpha = 0.5;
}

function ArgentinaBtn()
{
	defaultFade();
	root.page_map.interactive_map.Argentina.alpha = 1;
}

root.page_map.interactive_map.Argentina.addEventListener("click", ArgentinaBtn);

 

I hope it helps.

 

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
Explorer ,
Mar 22, 2022 Mar 22, 2022

Copy link to clipboard

Copied

thanks that perfect... i thought i had tried that.

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 ,
Mar 22, 2022 Mar 22, 2022

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