Salve, sono sempre quello degli oggetti "color".
All'apparenza c'è un bug nel metodo "ConvertToHex" che ho scritto perché non mi compare nessun alert come invece mi auspico. Il metodo si appoggia a sua volta ad una funzione "Translate(P)" che traduce P, uno dei parametri del mio colore (R, G o B) in esadecimale. Ma lascio che il codice si spieghi da solo:
===(inizio script)===
function color(R,G,B)
{
this.R = R || 0;
this.G = G || 0;
this.B = B || 0;
// eccetera...
this.ConvertToHex = function()
{
var sR,sG,sB;
sR = Translate(this.R);
sG = Translate(this.G);
sB = Translate(this.B);
alert(sR+sG+sB);
}
}
function Translate(P)
{
var S;
if (parseInt(P/16,10)<=9) S=(parseInt(P/16,10)*10);
else if (parseInt(P/16,10)==10) S="a";
else if (parseInt(P/16,10)==11) S="b";
else if (parseInt(P/16,10)==12) S="c";
else if (parseInt(P/16,10)==13) S="d";
else if (parseInt(P/16,10)==14) S="e";
else if (parseInt(P/16,10)==15) S="f";
if (P%16<=9) S+=(P%16);
else if (P%16==10) S+="a";
else if (P%16==11) S+="b";
else if (P%16==12) S+="c";
else if (P%16==13) S+="d";
else if (P%16==14) S+="e";
else if (P%16==15) S+="f";
return S;
}
===(fine script)===
Come vedete, alla fine dovrebbe eseguire alert(sR+sG+sB); ma non ci arriva mai. Né mi dà messaggi di errore. Non capisco come mai. Come si fa a vedere i "passi" che lo script svolge per fare un debug? Oppure, qualcuno di voi ha scovato l'errore a occhio?
Help!!!![]()
![]()
Andrea