Comunidad de diseño web y desarrollo en internet online

cargar imagen con xml

Citar            
MensajeEscrito el 19 Jun 2007 04:11 am
Hola! les comento que tengo un campo de texto dinamico donde cargo las las noticias con el titulo y quisiera cargar una imagen a cada noticia. Se puede hacerlo dentro del campo de texto o a la imagen la tengo que poner dentro de un movie clip. Aca les paso el codigo, que tengo que agregarle para que me ponga la imagen.

var newsXML:XML = new XML();
newsXML.ignoreWhite = true;
var output:String = "";

newsXML.onLoad = function(success) {
if (success) {

var news:Array = newsXML.firstChild.childNodes;
for(i=0;i<news.length;i++) {
output += "<b>";
output += news[i].childNodes[0].firstChild.nodeValue;
output += "</b> - <i>";
output += news[i].childNodes[1].firstChild.nodeValue;
output += "</i>\n";
output += news[i].childNodes[2].firstChild.nodeValue;
output += "\n\n";

}
news_txt.htmlText = output;
}
else
{
news_txt.text = "XML anda para el culo.";
}

}

newsXML.load("news2.xml");

Por rulera

11 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 21 Jun 2007 09:50 am
Hola,

Pues la verdad es q yo haría un MC que contuviera el campo output para el texto y un MC imagen para cargar la imagen q quieras.
Así puedes controlar si quisiera o no mostrar la imagen en un futuro.

Saludos

Por sebasstian

50 de clabLevel



Genero:Masculino  

Barcelona

firefox
Citar            
MensajeEscrito el 21 Jun 2007 05:30 pm
Podes cargarlo dentro de un campo de texto dinamico en formato html:
Example:
Creas un campo de texto dinamico y le pones de nombre de instancia "texto", luego pegas este codigo en el mismo frame q esta la foto en tu pelicula.

Código :

this.texto.html = true;
this.texto.htmlText = "<img src='chica.jpg' hspace='10'></img>El nuevo tag IMG 23 Setiembre 2003. Una cosa que puede resultar interesante, es que ahora FMX 2004 soporta el tag HTML <img> dentro de campos de texto dinamicos.";
stop();


para que sea dinamico puiedes hacer:

Código :

this.texto.htmlText = "<img src='"+nombreVar_img+"' hspace='10'></img>.......texto.....";

y listo, en donde dice "nombreVar_img" es una variable donde carga el nombre correspondiente a la imagen.
abrazo

Por index000

24 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 22 Jun 2007 03:20 am
Gracias sebasstian y index000 por sus respuestas, ya he solucionado todo y me funciona
Saludos..

Por rulera

11 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 22 Jun 2007 03:32 am
index000 de la forma que me dijiste no me lee nada de mi XML, o sea funciona bien porque me pone una imagen y el texto abajo, ahora para mostrar varias imagenes con texto, pero siempre y cuando lea todo de un xml
bueno si no me entiendes me avisas

Por rulera

11 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 26 Jun 2007 02:33 am
Hola!! tengo este codigo el cual me carga una noticia con un titulo, una de bajo de la otra. Lo que quiero hacer es que me cargue desde el archivo xml una imagen para cada noticia y no lo consigo. En flash tengo un texto dinamico donde van las noticias. Si alguien puede ayudarme le agradecere.

CODIGO

var newsXML:XML = new XML();
newsXML.ignoreWhite = true;
var output:String = "";

newsXML.onLoad = function(success) {
if (success) {

var news:Array = newsXML.firstChild.childNodes;
for(i=0;i<news.length;i++) {
output += "<b>";
output += news[i].childNodes[0].firstChild.nodeValue;
output += "</b> - <i>";
output += news[i].childNodes[1].firstChild.nodeValue;
output += "</i>\n";
output += news[i].childNodes[2].firstChild.nodeValue;
output += "\n\n";

}
news_txt.htmlText = output;
}
else
{
news_txt.text = "XML NO FUNCIONA.";
}

}

newsXML.load("news2.xml");

Por rulera

11 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 26 Jun 2007 02:50 am
Mira, en si lo que tienes q hacer es crear en el xml un nuevo nodo por cada noticia ej:

Código :

<titulo>sddgsdf s fgh fdgh dfg</titulo>
<img>img.jpg</img>


Luego debes leerlo y mostrarlo, ejemplo:
output += <img scr='carpeta_de_la_imagen'+news[i].childNodes[3].firstChild.nodeValue <img/>


Ejemplo con tu codigo

Código :

for(i=0;i<news.length;i++) {

output += <img scr='carpeta_de_la_imagen'+news[i].childNodes[3].firstChild.nodeValue <img/>

output += "<b>";
output += news[i].childNodes[0].firstChild.nodeValue;
output += "</b> - <i>";
output += news[i].childNodes[1].firstChild.nodeValue;
output += "</i>\n";
output += news[i].childNodes[2].firstChild.nodeValue;
output += "\n\n"; 


Con esto deberia funcionar, cualquier cosa avisa.
saludos

Por index000

24 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 26 Jun 2007 03:17 am
ME DA ERROR EN ESTA LINEA, ME DICE ALGO DE QUE DEBE SEGUIDO POR UN OPERANDO
output += <img scr='image'+news[i].childNodes[3].firstChild.nodeValue <img/>

Por rulera

11 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 26 Jun 2007 12:29 pm
output += <img scr='image'+news[i].childNodes[3].firstChild.nodeValue />

Por index000

24 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 26 Jun 2007 01:00 pm
Perdon index por la insistendia pero me sigue saliendo este error

**Error** Escena=Escena 1, capa=acciones, fotograma=1:Línea 7: El operador '+=' debe ir seguido de un operando
output += <img scr='image'+news[i].childNodes[3].firstChild.nodeValue />

Por rulera

11 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 26 Jun 2007 02:03 pm

Código :

output += "<img scr='image'"+news[i].childNodes[3].firstChild.nodeValue+" />";

Por One

Claber

1488 de clabLevel

5 tutoriales

Genero:Masculino  

Programador Web

firefox
Citar            
MensajeEscrito el 26 Jun 2007 09:41 pm
Ahora el codigo esta bien pero no me funciona lo mismo poniendo las imagenes en una carpeta.
XML
<news>
<story>
<title>Marcelo Rullan</title>
<date>8 de octubre de 2007</date>
<body>Lectores de Infobae.com enviaron su opinión sobre las declaraciones de ambos militantes kirchneristas. Tanto el filósofo cómo el frustrado diputado habían tildado de "fascistas" a los porteños que acompañaron a Macrin el gordito</body>
</story>

<story>
<title>Diego Theiler</title>
<date>Un integrante del seleccionado que ganó el Mundial de 1978 criticó duramente la vuelta de Verón a la Selección. Lo consideró como "un factor negativo" para el grupo. Opinó sobre todos los temas. </date>
<body>Nacio en justiniano posse un 20 de enero de 1978</body>
<img>riquelme.jpg</img>
</story>

<story>
<title>Seleccion mayor Copa America</title>
<date>18 de octubre de 2010</date>
<body>David Nalbandian, Guillermo Cañas y Juan Martín Del Potro, las tres máximas esperanzas argentinas comenzaron con un triunfo su participación en el tradicional torneo de Wimbledon, tercer Grand Slam de la temporada.</body>
</story>

<story>
<title>Murio Rugby Cordobes</title>
<date>26 de junio de 2007</date>
<body>El médico del Barcelona dio los detalles, algunos inexplicables, sobre el fallecimiento de Ramiro Loyola, el argentino que jugaba en el club español. Un hecho que deja inquietudes y puntos sin esclarecer.</body>

</news>
y las acciones en flash serian estas.
newsXML.onLoad= function(success) {
if(success) {
var news:Array = newsXML.firstChild.childNodes;
for (i=0;i<news.length;i++) {
output += "<img scr='image'"+news[i].childNodes[3].firstChild.nodeValue+" />";
output += "<b>";
output += news[i].childNodes[0].firstChild.nodeValue;
output += "</b> - <i>";
output += news[i].childNodes[1].firstChild.nodeValue;
output += "</i>\n";
output += news[i].childNodes[2].firstChild.nodeValue;
output += "\n\n";

}
news_txt.htmlText = output;
}
else
{
trace("No se puede leer el xml");
}
}
newsXML.load("news2.xml");

Por rulera

11 de clabLevel



Genero:Masculino  

msie7

 

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