array count returned as 1 but more than 1 items in xml
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: array count returned as 1 but more than 1 items in xml

  1. #1
    Senior Member
    Join Date
    Apr 2009
    Posts
    117

    array count returned as 1 but more than 1 items in xml

    text displaying only 1's item also array length trace shows count as 1

    xml code
    Code:
    <content>
    	<item>
    				<name>apple </name>
    				<type>- fruit </type>
    				<color>- red </color>
    				
    			
    	</item>
            <item>
    				<name>grapes</name>
    				<type>- fruit </type>
    				<color>- green </color>
    				
    			
    	</item>
            <item>
    				<name>raddish</name>
    				<type>- veggie </type>
    				<color>- white </color>
    				
    			
    	</item>
    
    </content>
    as2

    Code:
    var shoplistXML:XML = new XML();
    shoplistXML.ignoreWhite=true;
    var output:String ="";
    
    shoplistXML.load("shoplist.xml"):
    shoplistXML.onLoad= function(success) 
    {
    	if (success) 
    	{
    		var shoplist_content:Array = shoplistXML.firstChild.childNodes;
    		trace(shoplist_content.length);		
    		for (i=0;i<shoplist_content.length;i++)
    			{
    			output += shoplist_content[1].childNodes[0].firstChild.nodeValue;
    			output += "<b>";
    			output += shoplist_content[1].childNodes[1].firstChild.nodeValue;
    			output += "<\b>";
    			output += shoplist_content[1].childNodes[2].firstChild.nodeValue;
    			output += "\n";
    			output += shoplist_content[1].childNodes[3].firstChild.nodeValue;
    			output += "\n\n";
    			}
    		  list_txt.htmlText = output;
    	}
    }
    Last edited by glassfairy; 01-16-2013 at 08:10 PM.

  2. #2
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    Code:
    var shoplistXML:XML = new XML();
    shoplistXML.ignoreWhite=true;
    var output:String ="";
    
    shoplistXML.load("shoplist.xml"):
    shoplistXML.onLoad= function(success) 
    {
    	if (success) 
    	{
    		var shoplist_content:Array = shoplistXML.firstChild.childNodes;
    		trace(shoplist_content.length);		
    		for (i=0;i<shoplist_content.length;i++)
    			{
    			output += shoplist_content[i].childNodes[0].firstChild.nodeValue;
    			output += "<b>";
    			output += shoplist_content[i].childNodes[1].firstChild.nodeValue;
    			output += "<\b>";
    			output += shoplist_content[i].childNodes[2].firstChild.nodeValue;
    			output += "\n";
    			output += shoplist_content[i].childNodes[3].firstChild.nodeValue;
    			output += "\n\n";
    			}
    		  list_txt.htmlText = output;
    	}
    }

  3. #3
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    ok i got it working...thanx

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

Poll by Flashkit.com