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

ANIMATE CC: Adding a property through a forEach loop to various objects of THIS canvas

Community Beginner ,
Sep 18, 2019 Sep 18, 2019

Hi,

The aim is to make a figure, consisting of several parts, semi-transparent when it is clicked. While this works fine calling every single element of the figure individually, it would be nice to loop this call with an array. But doing so produces the error that "_this.element is undefined. What this the problem with the code?

 

_this.mc_Body.addEventListener('click', fn_AgentGlow.bind(_this));

//The short version (not working)
function fn_AgentGlow(){
	var agent = ["mc_LegLeft", "mc_LegRight", "mc_Torso", "mc_Scalp", "mc_ArmLeft", "mc_HandLeft", "mc_ArmRight", "mc_Handright"];
	agent.forEach( element => { _this.element.alpha = 0.5;
	});
}

//The long version (working)
function fn_AgentGlow(){
	_this.mc_Torso.alpha = 0.5;
	_this.mc_Skull.alpha = 0.5;
	_this.mc_LegLeft.alpha = 0.5;
	_this.mc_LegRight.alpha = 0.5;
	_this.mc_ArmLeft.alpha = 0.5;
	_this.mc_HandLeft.alpa = 0.5;
	_this.mc_ArmRight.alpha = 0.5;
	_this.mc_HandRight.alpha = 0.5;
}

 

As always, thank you for any help.

___________________________________________________________________________________________________

NOTE TO MODERATOR: Please move this post to Adobe Animate. Apologies

387
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 ,
Sep 18, 2019 Sep 18, 2019

Please post the name of the program you use so a Moderator may move this message to that forum
-A program would be Photoshop or Dreamweaver or Muse or Premiere Pro or ???

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 ,
Sep 19, 2019 Sep 19, 2019
LATEST

I found a workaround, though it is still not as sleek a code as I hoped it could be. But at least there is a bit of progress when storing the list of objects as complete variables in an array.

_this.mc_Body.addEventListener('click', fn_AgentGlow.bind(_this));

function fn_AgentGlow(){
	var agent = [_this.mc_LegLeft, _this.mc_LegRight, _this.mc_Torso, _this.mc_Scalp, _this.mc_ArmLeft, _this.mc_HandLeft, _this.mc_ArmRight, _this.mc_Handright];
	agent.forEach( element => { 
		_this.element.alpha = 0.5;
	});
}

Please come forward if you can come up with a better solution.

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