Skip to main content
Participant
December 8, 2020
Question

changing the alpha of a movieclip

  • December 8, 2020
  • 2 replies
  • 428 views

Hello,  (using adobe animate)

How do I change the alpha of one movieclip by clicking on another movieclip ?

One movieclip is a button that is supposed to change the other movieclip's transparency.

 

How do I write the code so each time when I click the button, the other movieclip's tranparency changes from 100 to 50, then from 50 to 0, and then back again to 50, then to 100?

 

Please help me as soon as possible, thank you so much 

This topic has been closed for replies.

2 replies

AdrianaCampolina
Participating Frequently
December 17, 2020

If you are using AS3, a variable can help you control the code: See this example:

 

// AS3

var alphaProgress: Boolean = true;

mc1.addEventListener(MouseEvent.CLICK, fnAlpha);
function fnAlpha(event: MouseEvent): void {

if ((alphaProgress == true) && (mc2.alpha > 0)) {
mc2.alpha -= 0.5;
trace(mc2.alpha);
} else if (mc2.alpha <= 0.5) {
alphaProgress = false;
mc2.alpha += 0.5;
trace(mc2.alpha);
if (mc2.alpha == 1) {
alphaProgress = true;
}
}
}

kglad
Community Expert
Community Expert
December 8, 2020

if html5:

 

this.toggle=-1;

this.control_mc.addEventListener("click",controlF.bind(this));

function controlF(){

this.target_mc.alpha += .5*this.toggle;

if(this.target_mc.alpha<.1 || this.target_mc.alpha>.9){

this.toggle*= -1;

}

}