Using functions

I have a problem with functions.

I have a function:

function changeColor(movieclip,color) {
…code here…
}

and I have 2 movieclips: square and circle. Once the whole movie starts, I do this:

square.onEnterFrame = changeSquareColor;
function changeSquareColor() {
changeColor(square,0xff0000);
}

circle.onEnterFrame = changeCircleColor;
function changeCircleColor() {
changeColor(circle,0x999999);
}

The result is that both movieclips change to the same color 0x999999.

Why is that?

Help, please


circle.onEnterFrame = function {
changeColor(this,0x999999);
}
square.onEnterFrame = function () {
changeColor(this,0xff0000);
}

that should work…

Jubba,

could you possibly explain why what you put should work and what paisley had wouldnt please.

I’m still learning so it’ll help, just curious.

Regards,
Viru.

Although he was defining 3 functions to change the movieclips color, i dunno why it wasnt working. Maybe if he points what was the changeColor function. :-
The following would have worked:[AS]function changeColor(movieclip, RGB) {
myColor = new Color(movieclip);
myColor.setRGB(RGB);
}
square.onEnterFrame = changeSquareColor;
function changeSquareColor() {
changeColor(square,0xff0000);
}

circle.onEnterFrame = changeCircleColor;
function changeCircleColor() {
changeColor(circle,0x999999);
}[/AS]But as Jubba pointed, could be replaced for:[AS]function changeColor(movieclip, RGB) {
myColor = new Color(movieclip);
myColor.setRGB(RGB);
}
square.onEnterFrame = function() {
changeColor(this, 0x336699);
};
circle.onEnterFrame = function() {
changeColor(this, 0x990000);
};[/AS]
But if he had used the following code, both circle and square will be set to 0x990000.[AS]circle.onEnterFrame = changeColor(this, 0x990000);[/AS]Or maybe he was pointing the setRGB method to “this”[AS]function changeColor(movieclip, RGB) {
myColor = new Color(this); //all mcs would have its RGB set to the same color
myColor.setRGB(RGB);
}[/AS]