Well this is what I have spent a large part of my morning trying to figure out. I think one of the biggest blocks I have in being able to write these things myself is that some things do not seem to have one definate thing that they do.
You know what I mean? Like they have a specific job they do but the details of that job can be so different and the job can be done in so many places. Maybe I am getting too abstract trying to explain that L
Anyway, back to what I did this morning, went through the code and commented it trying to make myself understand why it is working, so here goes:
[COLOR=Navy]stop();
[COLOR=DarkRed]//myArray stores the mcs that will change color[/COLOR]
myArray = [mystate27, mystate17, mystate30, mystate21, mystate6, mystate5, mystate45, mystate42, mystate29];
[COLOR=DarkRed]//these target the 5 buttons and sets the color object for each button
//which is used to store the color that will be applied to the mcs when the
//button is pressed, not the actual button color[/COLOR]
color0.col = 0x990000;
color1.col = 0x9966CC;
color2.col = 0xFFFF99;
color3.col = 0x9999FF;
color4.col = 0xFF9900;
[COLOR=DarkRed]//this is a loop that sets a variable equal to the length of (how many mcs are in)
//the array?[/COLOR]
for (var g = 0; g<myArray.length; g++) {
[COLOR=DarkRed]//takes the mc’s in the array which have been defined as the variable g
//and sets a new color object with the variable name “myColour”
//and we will leave it spelled in the British way in honor of Stringy =)
//this new color object is the original color of the mcs[/COLOR]
myArray[g][“myColour”+g] = new Color(myArray[g]);
[COLOR=DarkRed]//this defines the color property of g (all the mcs in the array)
//and stores the color in the myColour object using getTransform
//(getTransform is a new object which specifically stores that
//original color?, for this instance of the color object)[/COLOR]
myArray[g].col = myArray[g][“myColour”+g].getTransform();
}
[COLOR=DarkRed]//this is another loop which sets a varible j that applies 5 times
//meaning that it will execute this function for each of the 5 buttons[/COLOR]
for (var j = 0; j<5; j++) {
[COLOR=DarkRed]//it pulls the value of the color object set for the buttons
//and when the button is pressed executes the function
//the function uses another loop with a variable which again
//looks at the length of the array to allow it to apply the function
//to each mc in stored in the array
//a new color object is created for the array and the color of the mcs
//is changed with the setRGB to the color value stored in the button
//color object[/COLOR]
this[“color”+j].onPress = function() {
for (var i = 0; i<myArray.length; i++) {
myColour = new Color(myArray*);
myColour.setRGB(this.col);
}
};
}
[COLOR=DarkRed]//when the reset button is pressed the function again uses a variable in a
//loop so that the result is applied at all mcs stored in the array
//it calls upon the color property and uses setTransform to retrive
//what was stored with getTransform in that color object[/COLOR]
reset.onPress = function() {
for (k=0; k<myArray.length; k++) {
myArray[k][“myColour”+k].setTransform(myArray[k].col);
}
};[/COLOR]
Please if you would, make any corrections or more comments.