Solved

preventing blank xml records outputting as undefined

Posted on 2006-07-13
2
231 Views
Last Modified: 2006-11-18
in my xml file i have a part of it that goes like this

<store>
<name>Harvey Norman Outlets</name>
<address></address>
<suburb></suburb>
<postcode></postcode>
<phone></phone>
</store>

which when it is output through flash it outputs as
Harvey Norman Outlets
undefined
undefined
undefined
undefined

in the dynamic text. thanks to aneeshchopra ive got all the stores to output now, but now i'm just left with this one problem there.

this is the code in the flash file.

function loadXML(loaded) {

if (loaded) {
dB = new Array();
for(var i =0; i < xmlData.firstChild.childNodes.length; i ++){
// this.firstChild.childNodes[] refers to which store record you refer to
// this.firstChild.childNodes[].ChildNodes[0] refers to the store name
// this.firstChild.childNodes[].ChildNodes[1] refers to the store address
// this.firstChild.childNodes[].ChildNodes[2] refers to the store suburb
// this.firstChild.childNodes[].ChildNodes[3] refers to the store phone

_root.presentation.Retailers.waslide.waholder.text += this.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue +  newline + this.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue + newline + this.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue + newline + this.firstChild.childNodes[i].childNodes[3].firstChild.nodeValue + newline + newline;
}
} else {
trace("file not loaded!");
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("wa.xml");

thanks
0
Comment
Question by:paulp75
2 Comments
 
LVL 14

Expert Comment

by:trigger-happy
ID: 17098975
Try to add a little if statement in there that will check if the value of that certain node is undefined. If so then change the value to something else like an empty space " " so that you won't see the undefined message.

--trigger-happy
0
 
LVL 37

Accepted Solution

by:
CyanBlue earned 500 total points
ID: 17104040
What trigger-happy is saying is like this...

function loadXML(loaded)
{
      if (loaded)
      {
            dB = new Array();
            for(var i =0; i < xmlData.firstChild.childNodes.length; i ++)
            {
                  // this.firstChild.childNodes[] refers to which store record you refer to
                  // this.firstChild.childNodes[].ChildNodes[0] refers to the store name
                  // this.firstChild.childNodes[].ChildNodes[1] refers to the store address
                  // this.firstChild.childNodes[].ChildNodes[2] refers to the store suburb
                  // this.firstChild.childNodes[].ChildNodes[3] refers to the store phone
                  
                  var _store = this.firstChild.childNodes[i];
                  var _storeName = _store.childNodes[0].firstChild.nodeValue;
                  var _storeAddress = _store.childNodes[1].firstChild.nodeValue;
                  var _storeSuburb = _store.childNodes[2].firstChild.nodeValue;
                  var _storePhone = _store.childNodes[3].firstChild.nodeValue;
                  
                  if (_store == undefined) _store = "";
                  if (_storeName == undefined) _storeName = "";
                  if (_storeAddress == undefined) _storeAddress = "";
                  if (_storeSuburb == undefined) _storeSuburb = "";
                  if (_storePhone == undefined) _storePhone = "";
                  
                  _root.presentation.Retailers.waslide.waholder.text += _storeName +  newline + _storeAddress + newline + _storeSuburb + newline + _storePhone + newline + newline;
            }
      }
      else
      {
            trace("file not loaded!");
      }
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("wa.xml");

I think this sort of approach is whole lot more readable when you have to come back to the code like a month later...  That's the whole reason why I am replying to this topic...  ;)

CyanBlue
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now