Foros del Web » Creando para Internet » Flash y Actionscript »

Cargar datos xml en flash as2

Estas en el tema de Cargar datos xml en flash as2 en el foro de Flash y Actionscript en Foros del Web. Buenas mirar tengo 2 problemas. 1- Tengo este codigo: Código: var obj_xml:XML = new XML(); obj_xml.ignoreWhite = true; obj_xml.onLoad = function(exito) { if (exito) { ...
  #1 (permalink)  
Antiguo 18/03/2009, 15:14
 
Fecha de Ingreso: abril-2007
Mensajes: 26
Antigüedad: 16 años, 11 meses
Puntos: 0
Exclamación Cargar datos xml en flash as2

Buenas mirar tengo 2 problemas.
1- Tengo este codigo:
Código:
var obj_xml:XML = new XML();
obj_xml.ignoreWhite = true;
obj_xml.onLoad = function(exito) {
      if (exito) {
         articulo.text = obj_xml.firstChild.childNodes[0].firstChild.nodeValue;
         descripcion.text = obj_xml.firstChild.childNodes[1].firstChild.nodeValue;
         precio.text = obj_xml.firstChild.childNodes[2].firstChild.nodeValue;
         imagen = obj_xml.firstChild.childNodes[3].firstChild.nodeValue;
         _root.pantalla_mc.loadMovie(imagen);   
      } else {
         cuerpo_txt.text = "Error";
      }
   };
{
      obj_xml.load("OFERTAS-WEB.xml");
   }
Y mi problema es que no me carga la imagen, alguna sugerencia sobre esto?

2- Y el ultimo problema que me gustaria poner dos botones al de atras y siguiente pero me gustaria que el los dos botones no salieran a no ser que haya mas de una oferta, explico:
Si hay una oferta que no salga ninguno, si hay dos que solo salga el boton de siguiente y cuando vamos a la segunda oferta que salga el boton de atras y el de siguiente que desaparezca y asi sucesibamente.

Si alguien me puede ayudar se lo agradecesia mucho.
Un saludo a todos los forofos¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
  #2 (permalink)  
Antiguo 18/03/2009, 16:34
Avatar de Diegoazul  
Fecha de Ingreso: mayo-2007
Ubicación: { Dash Berlin }
Mensajes: 1.879
Antigüedad: 16 años, 9 meses
Puntos: 67
Respuesta: Cargar datos xml en flash as2

Intenta asi:

Código:
var obj_xml:XML = new XML();
obj_xml.ignoreWhite = true;
obj_xml.onLoad = function(exito) {
	if (exito) {
		articulo.text = obj_xml.firstChild.childNodes[0].firstChild.nodeValue;
		descripcion.text = obj_xml.firstChild.childNodes[1].firstChild.nodeValue;
		precio.text = obj_xml.firstChild.childNodes[2].firstChild.nodeValue;
		imagen = obj_xml.firstChild.childNodes[3].firstChild.nodeValue;
		_root.pantalla_mc.loadMovie(imagen);
	} else {
		cuerpo_txt.text = "Error";
	}
};

obj_xml.load("OFERTAS-WEB.xml");
  #3 (permalink)  
Antiguo 18/03/2009, 17:40
 
Fecha de Ingreso: abril-2007
Mensajes: 26
Antigüedad: 16 años, 11 meses
Puntos: 0
Exclamación Respuesta: Cargar datos xml en flash as2

Nada sigue sin funcionar de todas formas no he visto el cambio la imagen sigue sin salir no se poque al final me dare por vencido.

Un saludo¡¡¡¡¡¡¡¡¡¡¡¡¡¡
  #4 (permalink)  
Antiguo 18/03/2009, 17:51
Avatar de Diegoazul  
Fecha de Ingreso: mayo-2007
Ubicación: { Dash Berlin }
Mensajes: 1.879
Antigüedad: 16 años, 9 meses
Puntos: 67
Respuesta: Cargar datos xml en flash as2

A ver asi:

Código:
var obj_xml:XML = new XML();
obj_xml.ignoreWhite = true;
obj_xml.onLoad = function(exito) {
	if (exito) {
		articulo.text = obj_xml.firstChild.childNodes[0].firstChild.nodeValue;
		descripcion.text = obj_xml.firstChild.childNodes[1].firstChild.nodeValue;
		precio.text = obj_xml.firstChild.childNodes[2].firstChild.nodeValue;

		_root.pantalla_mc.loadMovie(String(obj_xml.firstChild.childNodes[3].firstChild.nodeValue));
	} else {
		cuerpo_txt.text = "Error";
	}
};

obj_xml.load("OFERTAS-WEB.xml");

Escribe tu archivo XML, ó si lo tienes en la web coloca la liga del xml.
  #5 (permalink)  
Antiguo 19/03/2009, 06:33
 
Fecha de Ingreso: abril-2007
Mensajes: 26
Antigüedad: 16 años, 11 meses
Puntos: 0
Exclamación Respuesta: Cargar datos xml en flash as2

Nada ya esta solucionado lo de la imagen solo tenia que quitarle el root a la linea:
_root.pantalla_mc.loadMovie(imagen);
tenia que ser:
pantalla_mc.loadMovie(imagen);

Asi que el tema de la imagen ya esta, ahora solo me queda el ultimo problema que me gustaria poner dos botones al de atras y siguiente pero me gustaria que el los dos botones no salieran a no ser que haya mas de una oferta, explico:
Si hay una oferta que no salga ninguno, si hay dos que solo salga el boton de siguiente y cuando vamos a la segunda oferta que salga el boton de atras y el de siguiente que desaparezca y asi sucesibamente. Pero todo sin tocar las lineas de codigo anteriores.Tengo este codigo pero no se que es lo que faya por que los datos me los carga pero no me carga los botones:

Código:
stop ();
var obj_xml:XML = new XML();
obj_xml.ignoreWhite = true;
but._x=-300;
but1._x=-300;
var num:Number=0;
obj_xml.onLoad = function(exito) 
{
	if (exito) 
	{

	    cargar(0);
	}
 
};
cargar =function(num:Number)
{
		articulo.text = obj_xml.firstChild.childNodes[0].firstChild.nodeValue;
		descripcion.text = obj_xml.firstChild.childNodes[1].firstChild.nodeValue;
		precio.text = obj_xml.firstChild.childNodes[2].firstChild.nodeValue;
		imagen = obj_xml.firstChild.childNodes[3].firstChild.nodeValue;
		pantalla_mc.loadMovie(imagen);
	} 
	obj_xml.load("OFERTAS-WEB.xml");
if(obj_xml.firstChild.childNodes[0].firstChild.childNodes[num+1]==null)
		but1._x=-200;
	else
	    but1._x=100;
    if(num==0)
	   but._x=-200;
	else
	   but._x=250;
Si alguien me puede ayudar se lo agradecesia mucho.
Un saludo a todos¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡

Última edición por Rubensfh; 19/03/2009 a las 07:20
  #6 (permalink)  
Antiguo 20/03/2009, 05:12
 
Fecha de Ingreso: abril-2007
Mensajes: 26
Antigüedad: 16 años, 11 meses
Puntos: 0
Respuesta: Cargar datos xml en flash as2

listo solucionado en mi caso el problema de la imagen para centrarla donde yo queria estaba en estas lineas:

Código:
target._x = (450 - target._width) / 2; 
         target._y = (380 - target._height) / 2;
he tenido que ir jugando con los numeros 450 y 380 para cuadrarlo con lo que queria.
al final se ha quedado asi:

Código:
var cargador_mcl:MovieClipLoader = new MovieClipLoader(); 
cargador_mcl.addListener( this ); 
 
function onLoadInit( target:MovieClip )  
{        
   target._width = Math.min( target._width, 334 );       
   target._height = Math.min( target._height, 260 );       
   target._x = (450 - target._width) / 2; 
   target._y = (380 - target._height) / 2;
} 
but._x = -200;  
but1._x = -200;  
var num:Number = 0;  
 
//-- XML --// 
var obj_xml:XML = new XML();  
obj_xml.ignoreWhite = true;  
obj_xml.onLoad = function( exito:Boolean )  
{  
   if (exito) cargar(0);  
}; 
obj_xml.load("OFERTAS-WEB.xml");  
 
function cargar( num:Number )  
{  
   articulo.text = obj_xml.childNodes[0].childNodes[num].childNodes[0].childNodes[0].nodeValue;  
   descripcion.text = obj_xml.childNodes[0].childNodes[num].childNodes[1].childNodes[0].nodeValue;  
   precio.text = obj_xml.childNodes[0].childNodes[num].childNodes[2].childNodes[0].nodeValue;  
   imagen =obj_xml.childNodes[0].childNodes[num].childNodes[3].childNodes[0].nodeValue;  
   cargador_mcl.loadClip( imagen, pantalla_mc ); 
   but1._x = (obj_xml.childNodes[0].childNodes[num+1]==null) ? -200 : 779.95;  
   but._x = (num==0) ? -200 : 628.8;  
}  
  
but.onRelease = function()  
{  
   num--;  
   cargar(num);  
}; 
  
but1.onRelease = function()  
{  
   num++;  
   cargar(num);  
}

hay estan los botones la carga de los datos y la imagen en su lugar para el diseño.

Un saludo¡¡¡¡¡¡¡¡¡¡¡¡¡¡
SOLUCIONADO
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:52.