I am trying to get a visual volume control type effect with movieclip boxes and clicking. So far I can do it, but the code is probably not optimal. I am trying to write it so I can include more or less movieclips in the future without rewriting all the code every time. Is there a better way to do this?
ActionScript Code:
var mc:MovieClip = new MovieClip();
mc.graphics.beginFill(0xFF0000);
mc.graphics.drawRect(60, 20, 100, 80);
mc.graphics.endFill();
mc.label = "mc"
addChild(mc);
var mc1:MovieClip = new MovieClip();
mc1.graphics.beginFill(0xCCFF00);
mc1.graphics.drawRect(60, 120, 100, 80);
mc1.graphics.endFill();
mc1.label = "mc1"
mc.addChild(mc1);
var mc2:MovieClip = new MovieClip();
mc2.graphics.beginFill(0x66CC66);
mc2.graphics.drawRect(60, 220, 100, 80);
mc2.graphics.endFill();
mc2.label = "mc2"
mc1.addChild(mc2);
var mc3:MovieClip = new MovieClip();
mc3.graphics.beginFill(0x63B8FF);
mc3.graphics.drawRect(60, 320, 100, 80);
mc3.graphics.endFill();
mc3.label = "mc3"
mc2.addChild(mc3);
mc.addEventListener(MouseEvent.CLICK, mc_clicked);
mc1.addEventListener(MouseEvent.CLICK, mc_clicked);
mc2.addEventListener(MouseEvent.CLICK, mc_clicked);
mc3.addEventListener(MouseEvent.CLICK, mc_clicked);
function mc_clicked(event:MouseEvent):void {
mc.alpha = 1
mc1.alpha = 1
mc2.alpha = 1
mc3.alpha = 1
if(event.target.alpha < 1){
event.target.alpha = 1;
}else{
event.target.alpha = .4;
}
}