Skip to main content
Inspiring
December 29, 2009
Answered

help loading xml data in a loop

  • December 29, 2009
  • 1 reply
  • 1109 views

hola amigos, acudo a ustedes porque estoy haciendo una pequeña aplicación que muestre archivos para mi nueva zona de descargas, está hecha utilizando diagramación líquida(gracias por los tutoriales que encontré aquí)y los datos de los archivos los carga desde un archivo xml.
Tengo un movieclip cargado con addChild, y que a su vez dentro carga tambien con addChild varios paneles utilizando un loop, la cosa es que quise utilizar ese mismo loop para que cada vez que cree un panel, ya le cargue los datos xml, pero no puedo hacerlo, me sale el error 1009 diciendo que el objeto es nulo. acá les dejo parte del código, por si alguno de ustedes me puede ayudar con eso.
Por adelantado les agradesco.

Hello folks, I come to you because I am doing a small application that shows files for my new download zone, it is done using liquid layout and the information of the files its loaded them from a file xml.
I have a movieclip loaded with addChild, and inside loads also with addChild several panels using a loop, the thing is that I wanted to use the same loop in order to each time add a new pannel, also load the information from xml, but I cannot do it, every time show my an error 1009 saying that the object is null(void). Here I leave you part of the code them, for if someone of you can help me with it.
In advance thanks for the help, and here its a sample of the API: http://nesmothdesign.com/media/home.swf

// define XML parameter

var imgLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("listado.xml"));
xmlLoader.addEventListener(Event.COMPLETE,      xmlLoaded);
function xmlLoaded(event:Event):void
{
xml = XML(event.target.data);
xmlList = xml.children();
trace(xmlList.length());
}

//add counter for the panns
var miContenedor:contenedor;
miContenedor = new contenedor();
addChild(miContenedor);
Tweener.addTween(miContenedor,{x:stage.stageWidth/2-465,time:1,transition:"easeIn"});
miContenedor.y = body_mc.y+10;
//add container´s children- -
var miPartA:panelTipoA;
var miPartB:panelTipoB;
for(var a:int=0;a<=3;a++)
{
miPartA = new panelTipoA();
miPartB = new panelTipoB();
miContenedor.addChild(miPartA);
miContenedor.addChild(miPartB);
miPartA.y = a * miPartA.height + (a*10);
miPartB.y = a * miPartB.height + (a*10);
miPartB.x = miPartB.width + 15;
imgLoader = new Loader();
imgLoader.load(new URLRequest(xmlList.attribute("thumb")));
miContenedor.miParteA.addChild(imgLoader);
}

Atention: the las 3 lines of code should add the data from xml to the respective pannel.

This topic has been closed for replies.
Correct answer kglad

sorry about that, its a term its not defined and dont have properties, so i think if cause have to put some input in loadF();

I tried to do this:

loadF(event:Event):void

{

for ......

}

but it didn´t work


miContenedor.miParteA.addChild(imgLoader);

is the problem.  there's no miContenedor.miParteA.  use:

miParteA.addChild(imgLoader);

1 reply

kglad
Community Expert
Community Expert
December 29, 2009

click file/publish settings/flash and tick "permit debugging" to pinpoint the line of code with the error.  if you don't understand how to correct the problem with that information highlight the problematic line of code.

kglad
Community Expert
Community Expert
December 29, 2009

your xml is loading AFTER you're trying to use it.  try:

// define XML parameter

var imgLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("listado.xml"));
xmlLoader.addEventListener(Event.COMPLETE,      xmlLoaded);
function xmlLoaded(event:Event):void {
    xml = XML(event.target.data);
    xmlList = xml.children();
    trace(xmlList.length());
    loadF();
}

//add counter for the panns
var miContenedor:contenedor;
miContenedor = new contenedor();
addChild(miContenedor);
Tweener.addTween(miContenedor,{x:stage.stageWidth/2-465,time:1,transition:"easeI n"});
miContenedor.y = body_mc.y+10;
//add container´s children- -
var miPartA:panelTipoA;
var miPartB:panelTipoB;


function loadF(){
for (var a:int=0; a<=3; a++) {
    miPartA = new panelTipoA();
    miPartB = new panelTipoB();
    miContenedor.addChild(miPartA);
    miContenedor.addChild(miPartB);
    miPartA.y = a * miPartA.height + (a*10);
    miPartB.y = a * miPartB.height + (a*10);
    miPartB.x = miPartB.width + 15;
    imgLoader = new Loader();
    imgLoader.load(new URLRequest(xmlList.attribute("thumb")));
    miContenedor.miParteA.addChild(imgLoader);
}
}