Question : flash as3 complicated button question

say i have 10 movieclips on stage that all have button functionality.
i also have 2 additional buttons.
when i click one of the buttons i want five of the movie clips to be 'deactivated': unclickable and grayed out.
when i click the other button the other five should be deactivated and the first five should be re-activated.

any advice on how i could do that with as3? or if you could point me to a tutorial somewhere.

thanks.

Answer : flash as3 complicated button question

Sorry, there was an erroneous trace action and misinformation in one of my comments.  Ignore the code in the last post, and use this.  Take care.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
// ------- AS2 Compliant --------------
// changeGroupState(GroupNumber:Number, EnabledState:Boolean);
 
var group1:Array = new Array();  // Group 1
var group2:Array = new Array();  // Group 2
var group3:Array = new Array();  // Group 3 
var pathToThis:MovieClip = this; // Path to Movie Clips
 
group1.push("MovieClip1");
group1.push("MovieClip2");
group1.push("MovieClip3");  // belongs to all groups
group1.push("MovieClip4");
group1.push("MovieClip5");
 
group2.push("MovieClip3");  // belongs to all groups
group2.push("MovieClip6");
group2.push("MovieClip7");
group2.push("MovieClip8");
group2.push("MovieClip9");
group2.push("MovieClip10");
 
group3.push("MovieClip3");  // belongs to all groups
group3.push("MovieClip4");
group3.push("MovieClip5");
group3.push("MovieClip8");
group3.push("MovieClip9");
 
button1.onRelease = function():Void {
     changeGroupState(1, false);  // Disable Group 1
     changeGroupState(3, false);  // Disable Group 3
     changeGroupState(2, true);   // Enable Group 2
}
 
button2.onRelease = function():Void {
     changeGroupState(2, false);  // Disable Group 2
     changeGroupState(3, false);  // Disable Group 3
     changeGroupState(1, true);   // Enable Group 1
}
 
function changeGroupState(g:Number, b:Boolean):Void {
     var thisGroup:Array = pathToThis["group"+ g];
     for(var i:Number=0; i< thisGroup.length; i++){
          var thisClip:MovieClip = pathToThis[thisGroup[i]];
          thisClip.enabled = b;
          thisClip._alpha = (b) ? 100 : 50; // Slight fade out
     }
}
 
 
 
// ------- AS3 Compliant --------------
// enableGroup( groupID:int );
 
var group1:Array = new Array();  // Group 1
var group2:Array = new Array();  // Group 2
var group3:Array = new Array();  // Group 3 
var pathToMCs:MovieClip = this; // Path to Movie Clips
 
group1.push("MovieClip1");
group1.push("MovieClip2");
group1.push("MovieClip3");  // belongs to all groups
group1.push("MovieClip4");
group1.push("MovieClip5");
 
group2.push("MovieClip3");  // belongs to all groups
group2.push("MovieClip6");
group2.push("MovieClip7");
group2.push("MovieClip8");
group2.push("MovieClip9");
group2.push("MovieClip10");
 
group3.push("MovieClip3");  // belongs to all groups
group3.push("MovieClip4");
group3.push("MovieClip5");
group3.push("MovieClip8");
group3.push("MovieClip9");
 
button1.addEventListener(MouseEvent.CLICK, buttonAction1);
button2.addEventListener(MouseEvent.CLICK, buttonAction2);
 
function buttonAction1(e:MouseEvent):void {
     enableGroup(1);
          /* The above is the same as doing the following:
         changeGroupState(2, false);
         changeGroupState(3, false);
         changeGroupState(1, true);  // Note: disable all other groups before enabling a group
         */
}
 
function buttonAction2(e:MouseEvent):void {
     enableGroup(2);
         /* The above is the same as doing the following:
         changeGroupState(1, false);
         changeGroupState(3, false);
         changeGroupState(2, true);  // Note: disable all other groups before enabling a group
         */
}
 
function enableGroup(n:int):void {
        for(var i:int = 1; typeof(this["group"+ i]) == "object"; i++){
                // Disable ALL groups
                changeGroupState(i, false);     
        }
        // Enable the specified group
        changeGroupState(n, true);
}
 
function changeGroupState(g:int, b:Boolean):void {
     var thisGroup:Array = this["group"+ g];
     for(var i:int=0; i< thisGroup.length; i++){
          var thisClip:MovieClip = pathToMCs[thisGroup[i]];
          thisClip.enabled = b;
          thisClip.alpha = (b) ? 1 : .5; // Slight fade out
     }
}
Open in New Window Select All
Random Solutions  
 
programming4us programming4us