Solved

preventing blank xml records outputting as undefined

Posted on 2006-07-13
2
230 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
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.

762 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

20 Experts available now in Live!

Get 1:1 Help Now