PDA

View Full Version : Changing MCs colour using an array & loop


acornFlyer
01-20-2006, 02:27 PM
I have 2 MCs (myClip01_mc and myClip02_mc) that I would like to change colour when a controlClip_mc is rolled over. I also have an array (colourArray) containing 20 colour values.

When controlClip_mc is rolled over, myClip01_mc should change colour to the first value in the array and myClip02_mc should change colour to the second value in the array. These colour changes should occur simultaneously.

While the mouse is still rolled over the controlClip_mc, after an interval (determined by a variable), myClip01_mc and myClip02_mc should then change colour to the third and fourth values contained in the array. After the same interval, they should then change to the fifth and sixth values in the array and so on until all of the colour values in the array have been used, after which the process starts again with the first and second colour values.

Conceptually, I know what should be happening here, but for some reason I really struggle with getting loops to do what I want them to and I'm really stuck here.

Can anyone help? Thanks in advance.

sophistikat
01-20-2006, 02:41 PM
can you show us what you have to far or what've attempted?
i would suggest sometime like....

// array of colors
var colours = ["0x000000", "0xFFFFFF"];

// setup a function to change the mc's color
function colorMe(mc, count){
var color_mc = new Color(mc);
color_mc.setRGB(colours[count]);
}

// loop that change our mc's color
for (var n = 0; n < colours.length; n++) {
colorMe(this["movieclip" + n], n);
}
this changes the colours of two pink movieclips on the stage too; one black and the other white

sibylhun
01-20-2006, 02:55 PM
Here is what I've understood :
This script change the value of the two txt fields box1_txt and box2_txt for the values in the array every 1sec... (1,2 then 3,4 etc.. and loop) then it's easyto apply this to the color of mcs...

var testArray:Array=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
var intervalSet:Number=0;
var i:Number=0;
var j:Number=1;

test_btn.onRollOver = function(){
if(!intervalSet){
intervalSet=1;
interval1 = setInterval(changeValue, 1000);
}
}
test_btn.onRollOut = function(){
clearInterval(interval1);
intervalSet=0;
i=0;
j=1;
}

function changeValue(){
if(j==19){
i=0;
j=1;
}
box1_txt.text =testArray[i];
box2_txt.text =testArray[j];
i+=2;
j+=2;
}

acornFlyer
01-20-2006, 04:28 PM
Lovely job. Thanks for these.