Comunidad de diseño web y desarrollo en internet online

Dar formato a un texto en tiempo de ejecucion

Citar            
MensajeEscrito el 10 Sep 2006 09:07 am

Código :

// TENGO UNA MATRIZ CON NUMEROS
numeros = ["0", "1", "2", "3", "4", "5"];
// Y OTRA VACIA
numeros2 = [""];
// A LA VACIA LE QUITO EL 1ER. VALOR PORQUE ESTA EN BLANCO
numeros2.shift();
// QUIERO LLENAR LA 2ª MATRIZ CON 9 NUMEROS ALEATORIOS COGIDOS
// DE LA MATRIZ 1.
for (var i = 0; i<9; i++) {
   numeros2.push(numeros[Math.floor(Math.random()*numeros.length)]);
}
// AHORA QUIERO QUE LOS REPRESENTE EN UN CAMPO DE TEXTO QUE TENGO EN
// EL ESCENARIO, PERO QUIERO QUE CADA 3 NUMEROS INSERTE UN SALTO DE LINEA
// PERO NO SE POR QUE INSERTA UN SALTO DE LINEA DESPUES DE CADA NUMERO
// Y LO HACE INCLUSO SI PRESCINDO DE LA ETIQUETA <BR>
for (var i in numeros2) {
   texto_txt.html = true;
   texto_txt.multiline = true;
   if (texto_txt.length%3 == 0) {
      texto_txt.htmlText += numeros2[i]//+"<BR>";
   } else {
      texto_txt.htmlText += numeros2[i];
   }
}
// YO QUIERO QUE QUEDE ASI:
// (Suponiendo que salieran estos numeros)
// 134
// 234
// 456

Por oxk4r

56 de clabLevel



 

Orense·España

firefox
Citar            
MensajeEscrito el 10 Sep 2006 09:13 am
for (var i in numeros2) {
texto_txt.html = true;
texto_txt.multiline = true;
if (i%3 == 0) {
texto_txt.htmlText += numeros2[i]+"<br>";
} else {
texto_txt.htmlText += numeros2[i];
}
}

Por _CONEJO

BOFH

7639 de clabLevel

17 tutoriales
21 articulos

 

clabbrowser
Citar            
MensajeEscrito el 10 Sep 2006 12:40 pm
Hola, tronko, gracias por tu respuesta, pero codificandolo asi, el texto muestra lo siguiente:
numero
numero
numero...
Es decir, cada uno en una linea, y yo necesito agruparlos para que en cada linea me aparezcan tres numeros:
numero,numero,numero
numero,numero,numero
numero,numero,numero...

:wink:

Por oxk4r

56 de clabLevel



 

Orense·España

firefox
Citar            
MensajeEscrito el 10 Sep 2006 12:48 pm
Déjate de texto html si sólo lo quieres para eso. usa el carácter \n para saltos de línea:

Código :

//texto_txt.html = true;
texto_txt.multiline = true;
for (var i in numeros2) {
   texto_txt.text += numeros2[i];
   if (i%3 == 0) {
      texto_txt.text += "\n";
   }
}

Por Zah

BOFH

4290 de clabLevel

27 tutoriales
5 articulos

  Bastard Operators From Hell Editores

Zaragoza, España

firefox
Citar            
MensajeEscrito el 10 Sep 2006 01:45 pm
Cojonudo tio, va perfecto.
Muchas gracias por tu ayuda. :love:

Por oxk4r

56 de clabLevel



 

Orense·España

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.