Copy link to clipboard
Copied
I have six symbols on the stage. When a user clicks each, I want it to lose most of its opacity. As a beginner, it seems like there are many ways to acheive this, but I'm not sure which way to go, and so far, haven't been able to do it. Do you get the transparency effect on separate timelines for each object or on the main timeline, or is it easier through js? Some basic setup advice would be appreciated.
no, that's irrelevant.
use:
this.dimmerA=["Mer_dimmer", "Jag_dimmer", "Cam_dimmer", "Mia_dimmer", "BM_dimmer", "Lex_dimmer"];
for(var i=0;i<6;i++){
this[this.dimmerA[i]].addEventListener("click",f.bind(this));
}
function f(e){
createjs.Tween.get(e.currentTarget).to({alpha:.1}, 1000);
}
-----------------------------------------------------------------------------------------------------------------------------------------
or use:
this.dimmerA=[this.Mer_dimmer, this.Jag_dimmer, this.Cam_dimm
...Copy link to clipboard
Copied
for others that don't want to download, the fla contains code from the first message:
for(var i=0;i<6;i++){
this["symbol_"+i].addEventListener("click",f.bind(this));
}
function f(e){
createjs.Tween.get(e.currentTarget).to({alpha:.1}, 1000);
}
this is all that's required to create fade-outs for 6 movieclips with instance names symbol_0, symbol_1,...,symbol_5
--------------------------------------------------------------------------------------------------------------------------------------------------
and this is a good example of how thoughtful name assignments can simplify coding. the coding can still be done with less thoughtful name choices, but it adds complications.
and if the op had 10,000 movieclip buttons, the code wouldn't be any more complicated or lengthy (though adding another 9,994 movieclips to the stage and assigning instance names would be time-consuming):
for(var i=0;i<10000;i++){
this["symbol_"+i].addEventListener("click",f.bind(this));
}
function f(e){
createjs.Tween.get(e.currentTarget).to({alpha:.1}, 1000);
}
Copy link to clipboard
Copied
In your example, there is one symbol with six different instances. In mine, there are six different symbols (because they are all different images converted to symbols). Is that why this isn't working for me?
Copy link to clipboard
Copied
no, that's irrelevant.
use:
this.dimmerA=["Mer_dimmer", "Jag_dimmer", "Cam_dimmer", "Mia_dimmer", "BM_dimmer", "Lex_dimmer"];
for(var i=0;i<6;i++){
this[this.dimmerA[i]].addEventListener("click",f.bind(this));
}
function f(e){
createjs.Tween.get(e.currentTarget).to({alpha:.1}, 1000);
}
-----------------------------------------------------------------------------------------------------------------------------------------
or use:
this.dimmerA=[this.Mer_dimmer, this.Jag_dimmer, this.Cam_dimmer, this.Mia_dimmer, this.BM_dimmer, this.Lex_dimmer];
for(var i=0;i<6;i++){
this.dimmerA[i].addEventListener("click",f.bind(this));
}
function f(e){
createjs.Tween.get(e.currentTarget).to({alpha:.1}, 1000);
}
-----------------------------------------------------------------------------------------------------------------------------------------
or rename your dimmer instance as suggested in the first message and use the code from the first message
Copy link to clipboard
Copied
Thanks kglad. This is still a bit hazzy to me, but at least it's working. I appreciate it.
Copy link to clipboard
Copied
you're welcome.