A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: (CS3 - AS2) Adding a "-" to string if a node is missing

  1. #1

    (CS3 - AS2) Adding a "-" to string if a node is missing

    Hi everyone,

    As a designer, I'm new to importing xml myself, but really liking the possibilities...BUT...I'm having a problem on my first attempt.

    I have been given and xml file to work with and it's not really changeable, here's an example...

     <?xml version="1.0" ?> 
      <club name="Benalla Golf Club">
      <club_name>Benalla Golf Club</club_name> 
      <club_address>Mansfield Road</club_address> 
      <club_phone>(03) 5762 1920</club_phone> 
      <club_proshop_phone>(03) 5762 2404</club_proshop_phone> 
      <club_fax>(03) 5762 6069</club_fax> 
      <club_midweek_addinfo /> 
      <club_weekend_addinfo /> 
    You'll notice the <club_midweek_addinfo> node. This node is only sometimes filled with content.

    here is an excerpt of the AS to display certain content in dynamic text...

    //List of items
    var golfclubs:XML = xmlLoad.firstChild;
    golfclubs.ignoreWhite = true;
    for (var m = 0; m<golfclubs.childNodes.length; m++) {
    	//grab each item
    if (golfclubs.childNodes[m].nodeName == "club") {
    for (var n = 0; n<golfclubs.childNodes[m].childNodes.length; n++) {
    if (golfclubs.childNodes[m].childNodes[n].nodeName == "club_name") {
    	//grab the name
    clubname = golfclubs.childNodes[m].childNodes[n].firstChild.toString();
    if (golfclubs.childNodes[m].childNodes[n].nodeName == "club_midweek_addinfo") {
    	//grab the midweek add info
    MWAddInfo = golfclubs.childNodes[m].childNodes[n].firstChild.toString();
    if	(golfclubs.childNodes[m].childNodes[n].nodeName == "club_weekend_addinfo") {
    //grab the weekend add info
    WEAddInfo = golfclubs.childNodes[m].childNodes[n].firstChild.toString();
    //add the current item to the text box
    textfield += "<u><font color='#6DB33F'>"+clubname+"</font></u><br>"+clubaddress+", "+clubsuburb+"</br><br>"+clubphone+"</br><br><br><font color='#6DB33F'>GFore Weekday Fee - $"+GFfee+"</br></font><font color='#666666'>   normally $"+mwstandard+"<br>additional information : "+MWAddInfo+"</font></br><br><br><font color='#6DB33F'>GFore Weekend Fee - $"+GFWEfee+"</br></font><font color='#666666'>   normally $"+weStandard+"<br>additional information : "+WEAddInfo+"</font></br><br><br><br>";
    				//set the text  
    		greenFeeText.htmlText = textfield;
    My problem is that I need to display the info when there is data in the node, and display some sort of generic character when there isn't data in the node eg. "-". But at the moment, once flash hits a missing node, it just repeats the previous data.

    I've tried adding another if statement such as...

    if	(golfclubs.childNodes[m].childNodes[n].club_weekend_addinfo == null) {
    					//grab the weekend add info
    						WEAddInfo = "-";
    ...but that just shows nothing at all, whether the data exists or not.

    As far as the xml is concerned, I don't really have much control over the format. I originally asked the guy to keep the node there but just have it empty. But that didn't work either...

    Any suggestions would be great as I'm approaching deadline!


  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    the empty node will be undefined, so use -
    PHP Code:
    if(golfclubs.childNodes[m].childNodes[n].nodeName == "club_weekend_addinfo") {
    WEAddInfo golfclubs.childNodes[m].childNodes[n].firstChild.toString();
    WEAddInfo == undefined ?  WEAddInfo "--" null;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center