LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-12-2005, 01:46 PM
PUP100 PUP100 is offline
Registered User
 
Join Date: Jan 2003
Location: UK
Posts: 145
Rep Power: 11
PUP100 is on a distinguished road
I have been having a lot of trouble understanding a code example from an XML reference book. The problem is not really XML specific but more to do with how Flash handles “loops” and “if” statements.I’d just state for those not up to speed with the only bit of XML you would need to know for this example, that XML nodes can have two values 1=element node and 3=text node.What this code does is loop through an XML document and add spacing to it so each child heading is indented from it’s parent.As I say this has little if nothing to do with XML, but to make the post clearer I will use the following XML file to show where I’m at with this:

Actionscript:
XMLNode.prototype.toString = function () {

        function spaceOut() {
                var sStr = \"\";
                for(var i=0;i<XMLNode.spaces;i++){
                        sStr += \" \";
                }
                return(sStr);
        }

        var xStr = \"\";
        XMLNode.spaces += 4;
        if (this.nodetype == 1) {
                //it's an element; check its kids
                xStr += spaceOut()+\"<\"+this.nodeName;
                var attr = this.attributes;
                for (var eachAttr in attr){
                        xStr += \" \" + eachAttr+\"='\"+this.attributes[eachAttr]+\"'\";
                }
                xStr +=\">\";
                if (this.firstChild.nodeType == 1){xStr += \"\n\";}
                var chlength = this.childNodes.length;
                for (var i=0;i < chlength; i++) {
                        xStr += this.childnodes[i].toString();
                }
                if (this.lastChild.nodeType==1){xStr += spaceOut();}
                xStr += \"</\"+this.nodeName+\">\n\";
                XMLNode.spaces -= 4;
        } else {
                //it's text
                xStr += this.nodeValue;
                XMLNode.spaces -= 4;
        }
        return(xStr);
}

Last edited by Scottae : 01-12-2005 at 02:40 PM Reason: Format with proper CODE and AS tags
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Button code problems sharareh Actionscript 2.0 4 04-13-2007 12:03 PM
Script problems (if statements...) MKratt Newbies 2 12-27-2005 04:45 PM
Problems with XML code from reference book. PUP100 XML & Sockets 0 01-07-2005 12:07 PM
Flash reference book for newbies amagab Newbies 3 12-07-2004 08:43 PM
Problems with "if" statement generating dynamic text. PUP100 Flash MX ActionScript 3 07-15-2003 04:43 PM




All times are GMT. The time now is 09:28 AM.