PDA

View Full Version : how can i make the movie clips to change color during runtime


mallgi01
12-06-2005, 04:54 AM
Hello everyone,
I have a attached a file with this post that contains the problem that I would like to address. Consider the following code:

for (i=0; i<5; i++) {
_root["rock"+i+"_mc"+row].input_txt.selectable = false;
_root["rock"+i+"_mc"+row].rock_mc._visible = true;
_root["rock"+i+"_mc"+row].rock_mc.gotoAndStop(8);
//addition
_root["rock"+i+"_mc"+row].rock_mc.onPress = function () {
_root["rock"+i+"_mc"+row].rock_mc.gotoAndStop(4);
}();
}


The problem is such that, I want to be able to click on the little rocks that appear at the top left corner of each box when th done button is pressed first. (These rocks are the part of the "square" movie clip and are named rock_mc. Here I have duplicated the squares at runtime. ) But the movie clip is not responding to my onPress command as I have shown above. I am really confused why this is not working. Can someone help me?
many thanks,

m

I have included my file with this post. Please refer to it if necessary.

amen0
12-06-2005, 01:26 PM
modify this function

function doneGuess() {
//trace("this row: "+row);
for (k=0; k<5; k++) {
x_array.push(_root["rock"+k+"_mc"+row].input_txt.text);
//trace("arrayLength: "+x_array.length);
}
// make all five button inactive
for (i=0; i<5; i++) {
//trace(_root["rock"+i+"_mc"+row])
_root["rock"+i+"_mc"+row].input_txt.selectable = false;
_root["rock"+i+"_mc"+row].rock_mc._visible = true;
_root["rock"+i+"_mc"+row].rock_mc.gotoAndStop(8);
//addition
//trace(_root["rock"+i+"_mc"+row].rock_mc._y)
_root["rock"+i+"_mc"+row].rock_mc.i=i;
_root["rock"+i+"_mc"+row].rock_mc.row=row;
_root["rock"+i+"_mc"+row].rock_mc.onPress = function () {
trace(this.i);
_root["rock"+this.i+"_mc"+this.row].rock_mc.gotoAndStop(4);
};
}
//check how many letters are correct
for (m=0; m<5; m++) {
for (n=0; n<5; n++) {
if (solution[n] == x_array[m]) {
matches++;
}
}
}
//show the number of letter that are in the solution
attachMovie("DynTxt_mc", "DynTxt_mc"+dep, dep);
_root["DynTxt_mc"+dep]._x = rightColLoc;
_root["DynTxt_mc"+dep]._y = topRowLoc+row*vertSpace;
_root["DynTxt_mc"+dep].numCorrect.text = matches;
dep++;
matches = 0;
// remove "done" button
done.removeMovieClip();
// see whether the player wins
if (x_array.toString() == solution.toString()) {
gotoAndPlay("win");
} else {
row++;
// see whether the player loses
if (row>=10) {
showSolution();
gotoAndPlay("lose");
} else {
createRow();
}
//trace(x_array.toString() == x_array.toString());
//empty the array
for (m=0; m<5; m++) {
x_array.pop();
}
//trace("after popping array length: "+x_array.length);
}
}

mallgi01
12-06-2005, 02:53 PM
That was a wonderful solution. Thanks a lot that works superb. Could you give me some explanation to why this might be the case? I think I know what is going on, but this is the first time that the instance had to be given that value. I would be grateful if you could clarify on this. Thank you once again!

amen0
12-06-2005, 10:18 PM
hi,
ur code was
_root["rock"+i+"_mc"+row].rock_mc.gotoAndStop(4);
i, and row when you r out of the for function they are gone that mean the MCs see them undefined so we pass them in this way...
and you were having a script unkown syntax
at the end of the for you typ
_root["rock"+i+"_mc"+row].rock_mc.onPress = function () {
_root["rock"+i+"_mc"+row].rock_mc.gotoAndStop(4);
}();
(); the () for what?
you don't need them.