ANIMATE CC: Adding a property through a forEach loop to various objects of THIS canvas
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
