Connecting Tech Pros Worldwide Forums | Help | Site Map

Problems reading a part of XML using AC3 ...

Newbie
 
Join Date: Aug 2007
Posts: 23
#1: May 14 '09
Hi

i can read everything from my xml file except a part that i can always get teh first items of each category (it will make more sence in a sec)

So here is my xml

[HTML]<?xml version="1.0" encoding="UTF-8"?>
<flashxml>
<second_page>
<sp text="ss ptextj"/>
<ss text="sptext"/>
<clas text="clas"/>
</second_page>
<third_page>
<ss>
<category name="categor">
<item>3333</item>
<item>H4444</item>
<item>etc etc etc </item>
</category>
<category name="security ">
<item>SSL</item>
<item>Hacke</item>
<item>etc etc etc </item>
</category>
</ss>
<sp>
<category name="security a">
<item>SSL lallalala</item>
<item>Hacker</item>
<item>etc etc etc </item>
</category>
<category name="onlin">
<item>Hussle free</item>
<item>Diafore</item>
<item>etc etc 2 </item>
</category>
</sp>
<classifieds>
<category name="Best">
<item>Additem1</item>
<item>Additem2</item>
<item>Additem3 </item>
</category>
</classifieds>
</third_page>
</flashxml>[/HTML]

I am trying for each category in the xml to get the relevant items ...

The problem is that if i try to read for e.g the second set of items for the second category of <sp> using a counter it throws a type error

TypeError: Error #1010: A term is undefined and has no properties.
at MethodInfo-1()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()

so the following works


Expand|Select|Wrap|Line Numbers
  1. var itemslist:XMLList = xml.third_page.ss.category[0].item; 
(it will always display the first items of the first category for all the categories

so for instance for sp will always return even for the second category

<item>SSL lallalala</item>
<item>Hacker</item>
<item>etc etc etc </item>



but when i am using

Expand|Select|Wrap|Line Numbers
  1. var itemslist:XMLList = xml.third_page.ss.category[i].item; 
i am getting the type error above TypeError: Error #1010 .. (no idea why)

Any help will be much appreciated

complete code ::


Expand|Select|Wrap|Line Numbers
  1. pp.buttonMode = true;
  2.  
  3. pp.addEventListener(MouseEvent.ROLL_OVER, onButtonOver);
  4. pp.addEventListener(MouseEvent.CLICK, onButtonOut);
  5.  
  6. function onButtonOver(e:MouseEvent):void
  7. {
  8.  e.currentTarget.gotoAndPlay("a");
  9.  var xmlString:URLRequest = new URLRequest("ev.xml");
  10. var xmlLoader:URLLoader = new URLLoader(xmlString);
  11. xmlLoader.addEventListener("complete", init);
  12. function init(event:Event):void{
  13.   var xDoc:XMLDocument = new XMLDocument();
  14.   xDoc.ignoreWhite = true;
  15.   var animalsXML:XML = XML(xmlLoader.data);
  16.    //var list:XML = XML(xml Loader.data);
  17.  // trace (animalsXML);  //prints the xml
  18.  
  19.   //edooooooooooooooooooooooooooooooooooo
  20.  var  xml = XML(xmlLoader.data);  
  21.  
  22.            trace ("XML File");   
  23.        trace ("===================");   
  24.            trace (xml.second_page.sp.attribute("text"));    
  25.       trace (xml.second_page.ss.attribute("text"));    
  26.       trace (xml.second_page.clas.attribute("text"));    
  27.  
  28.   //edoooooooooooooooooooooooooooooooooooooooooooooooooooo
  29.  
  30.  
  31.  // Third page ss
  32.    var i = 0;
  33.    var categorylist:XMLList = xml.third_page.ss.category;   
  34.  
  35.           for each (var captionElement:XML in categorylist)   
  36.            {   
  37.      i++;
  38.                trace (captionElement.attribute("name"));  
  39.     //trace (captionElement.item);
  40.  
  41.     var itemslist:XMLList = xml.third_page.ss.category[0].item; 
  42.  
  43.     for each (var captionElement:XML in itemslist)   
  44.            {   
  45.                 trace(captionElement);
  46.   // trace (valueOf(captionElement.item));
  47.  
  48.              }   
  49.  
  50.     }           
  51.  
  52.  
  53.  // Third page sp
  54.    var i = 0;
  55.    var categorylist:XMLList = xml.third_page.sp.category;   
  56.  
  57.           for each (var captionElement:XML in categorylist)   
  58.            {   
  59.      i++;
  60.                trace (captionElement.attribute("name"));  
  61.     //trace (captionElement.item);
  62.  
  63.     var itemslist:XMLList = xml.third_page.sp.category[0].item; 
  64.  
  65.     for each (var captionElement:XML in itemslist)   
  66.            {   
  67.                 trace(captionElement);
  68.   // trace (valueOf(captionElement.item));
  69.  
  70.              }   
  71.  
  72.  
  73.              }   
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  // Third page clas
  81.   var i = 0;
  82.    var categorylist:XMLList = xml.third_page.classifieds.category;   
  83.  
  84.           for each (var captionElement:XML in categorylist)   
  85.            {
  86. i++;
  87.            trace (i);
  88.      trace (captionElement.attribute("name"));
  89.     //   trace (captionElement.item);
  90.   // trace (valueOf(captionElement.item));
  91.     //var hi= captionElement.attribute("name");
  92.  
  93.  
  94.  
  95.  
  96.  var itemslist:XMLList = xml.third_page.classifieds.category[0].item; 
  97.  
  98.     for each (var captionElement:XML in itemslist)   
  99.            {   
  100.                 trace(captionElement);
  101.   // trace (valueOf(captionElement.item));
  102.  
  103.              }     
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.              }   
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.   for each(var itemData:XML in animalsXML.elements()) {
  119.  //  trace(itemData.elements().attribute("text")); //DOULEUI
  120. //third page
  121. //itemData.thirdpage.elements()[0].@patty 
  122. }
  123.  
  124.  
  125.   xDoc.parseXML(animalsXML.toXMLString());
  126.  
  127.  // trace(xDoc.firstChild.childNodes[0]); //Riverside
  128.   //trace(xDoc.firstChild.childNodes[0].nodeValue);
  129.  
  130. //trace(xDoc.valueOf(.getElementsByTagName("item")[0].childNodes[0].nodeValue);
  131.  
  132.  
  133.   }
  134.  
  135. }
  136. function onButtonOut(e:MouseEvent):void
  137. {
  138.  e.currentTarget.gotoAndPlay("b");
  139.  pb.gotoAndPlay("a");
  140. }

Reply