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

53

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , 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_...

Likes

Translate

Translate
Adobe Community Professional ,
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

 

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

Copy link to clipboard

Copied

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

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
community guidelines
Adobe Community Professional ,
Mar 22, 2022 Mar 22, 2022

Copy link to clipboard

Copied

LATEST

You're welcome.

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
community guidelines