Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

help loading xml data in a loop

Explorer ,
Dec 29, 2009 Dec 29, 2009

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.

TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 29, 2009 Dec 29, 2009

miContenedor.miParteA.addChild(imgLoader);

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

miParteA.addChild(imgLoader);

Translate
Community Expert ,
Dec 29, 2009 Dec 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 29, 2009 Dec 29, 2009

Hi Kglad, first of all thank you for your atention.

I made the debbugin and show the error en this line: imgLoader.load(new URLRequest(xmlList.attribute("thumb")));

for some reason show error 1009, but can´t understand why. imgLoader - load the link from my xmlList, and the attribute´s name is "thumb", variable a its a counter for the loopso I use it for the node number too.

here is how looks like the xml file:

<?xml version="1.0" encoding="utf-8"?>
<listado>
<auto thumb="img/1.jpg">tuto numero 1</auto>
<auto thumb="img/2.jpg">tuto numero 2</auto>
<auto thumb="img/3.jpg">tuto numero 3</auto>
<auto thumb="img/4.jpg">tuto numero 4</auto>
<auto thumb="img/5.jpg">tuto numero 5</auto>
<auto thumb="img/6.jpg">tuto numero 6</auto>

</listado>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2009 Dec 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);
}
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 29, 2009 Dec 29, 2009

It works, but now im getting an error 1010 from the loadF()  that mean that I have to put inside () the input?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2009 Dec 29, 2009

what's error 1010?  (i don't have them all memorized.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 29, 2009 Dec 29, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2009 Dec 29, 2009

miContenedor.miParteA.addChild(imgLoader);

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

miParteA.addChild(imgLoader);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 29, 2009 Dec 29, 2009

Thanks so much for all the help, finally its working, its been dificult to me , and if it wasn´t for your help dont know if I could finished, thank you friend, here is all the code so if someone found it useful can use it , the only thing it need is Caurina tweener. I will upload the file when its finished

import caurina.transitions.*;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;

//script para liquid layout
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener (Event.RESIZE, varDim);

// definicion de parametro XML
var imgLoaderA:Loader;
var imgLoaderB: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());
    loadFunc();
}

// initialize sizing
resizeHandler (null);

//estas variables almacenan dimensiones originales W H
var swOrig:Number = stage.stageWidth;
var shOrig:Number = stage.stageHeight;

//controlan posiciones originales de cada elemento(basic parts)
Tweener.addTween(header_mc,{x:0,y:0,width:swOrig, time:1, transition:"easeIn"});
Tweener.addTween(body_mc,{x:stage.stageWidth /2, y:header_mc.height,height:shOrig - header_mc.height - footer_mc.height, time:1, transition:"easeIn"});

//add cont con los paneles
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;
//agrega los childs del contenedor - -
var miPartA:panelTipoA;
var miPartB:panelTipoB;

function loadFunc(){
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;
imgLoaderA = new Loader();
imgLoaderB = new Loader();
imgLoaderA.load(new URLRequest(xmlList.attribute("thumb")));
miPartA.addChild(imgLoaderA);
imgLoaderB.load(new URLRequest(xmlList[a+1].attri...


//funcion principal para cuando cambia el tamaño
function varDim (event:Event):void {
  var sw:Number = stage.stageWidth;
  var sh:Number = stage.stageHeight;
  header_mc.width = body_mc.width = footer_mc.width = sw;
  body_mc.x = stage.stageWidth /2;
  body_mc.height = sh - header_mc.height - footer_mc.height;
  body_mc.y = header_mc.height;
  footer_mc.y = sh-footer_mc.height;
  Tweener.addTween(miContenedor,{x:stage.stageWidth/2-465,time:1,transition:"easeIn"});
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2009 Dec 29, 2009
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines