Solved

preventing blank xml records outputting as undefined

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Stock Videos 17 332
Missing Plugin for Firefox - Can't View Content 7 173
Animating text  - electrons orbit around letter M 12 79
Flash Converter 8 122
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
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 how to load their YouTube profile onto Flash Media Live Encoder.

773 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