Html 5 canvas, Controlling an object instance from a variable
Hi, this is my first time asking here and I think I got a super dumb error, I have a movieclip which contains several dynamic text fields that must be filled according to a player ranking, so I tought doing something like this:
window._this = this;
//ARRAY RANKING, this is the array that gets the time(tiempo) and the player(jugador) //
window._arrayRanking = [
{jugador:_jugadorActivo,tiempo:_tiempoFinal},
];
//// then I use this function, I use the console a lot to check my errors///
_this.Ranking = function() {
console.log(_arrayRanking.sort((a, b) => a.tiempo - b.tiempo ));
console.log(_arrayRanking.length);
for (let i = 0; i < _arrayRanking.length; i++) {
_this.mc_ranking.jugador_[i].text="Jugador "+_arrayRanking[i].jugador;
_this.mc_ranking.tiempo_[i].text=_arrayRanking[i].tiempo;
console.log("el for funciona");
}};
My brain tells me that this must work, even when i turn this line (_this.mc_ranking.jugador_[i]) into a variable (var jugadorR="_this.mc_ranking.jugador_"+i, and then try jugadorR.text= "xxx") and put it in the console it shows _this.mc_ranking.jugador_0 or _1 but for some reason it doesnt control the text field which i need to control, it also happens when i try to control a movieclip instance (say _this.mc_ranking.jugador_[i].visible= false;) so as a Machete type solution i used a switch case for every one of the 15 players which gave me like 100 more lines of code. I want to know why that happens and how can I solve it in the future, thanks.
