XML, dataGrid, cellPress?!?!?!?!?

  • zalienjoe
  • Born
  • Born
  • zalienjoe
  • Posts: 1

Post 3+ Months Ago

Hello all, first post! I'm pretty much a n00b when it comes XML integration, data Arrays ect ect, but I'm not a complete Flash/Action Script n00b.

I'm trying to have a list of items created from my XML data listed in a dataGrid. I then want to show attributes of each item when clicked.

I started a simple application to try and get the core function working, but I'm stuck. I'm doing something wrong when trying to trace the Shape attribute from the Array. It just traces the last item's Shape attribute. I'm pretty sure I need to either setup another array for the shape attribute, or setup the Shape variable within the Listener Object, but I really just do'nt have a clue at this point. Please help! :cry:

Here's what I have:

Code: [ Select ]
function parseXML(){
  myXML = new XML();
  myXML.load("items.xml");
  myXML.ignoreWhite = true;
  myXML.onLoad = function(success){
   if(success){
     trace("xml loaded...");
     makeArray();
        
   }else{
     trace("xml load failed...");
   }
  }
}

function makeArray(){
  parseArray = [];
  nodes = myXML.firstChild.childNodes;
  for(var i=0;i<nodes.length;i++){
     
     title = nodes[i].attributes.title;
         color = nodes[i].attributes.color;
     shape = nodes[i].attributes.shape;
         parseArray.push({title:title,color:color});
         
     my_dg.dataProvider = parseArray

     
    }
}


var dgListener:Object = new Object();
dgListener.cellPress = function() {
    //var shape:Array = parseArray[i].shape;
    var shape:Array = nodes.shape(this.firstChild, "shape"+i,i);
    trace("shape is "+shape+" !");
    //itemShape.text = this.nodes[i].shape;
};

// Add listener.
my_dg.addEventListener("cellPress", dgListener);


parseXML();
  1. function parseXML(){
  2.   myXML = new XML();
  3.   myXML.load("items.xml");
  4.   myXML.ignoreWhite = true;
  5.   myXML.onLoad = function(success){
  6.    if(success){
  7.      trace("xml loaded...");
  8.      makeArray();
  9.         
  10.    }else{
  11.      trace("xml load failed...");
  12.    }
  13.   }
  14. }
  15. function makeArray(){
  16.   parseArray = [];
  17.   nodes = myXML.firstChild.childNodes;
  18.   for(var i=0;i<nodes.length;i++){
  19.      
  20.      title = nodes[i].attributes.title;
  21.          color = nodes[i].attributes.color;
  22.      shape = nodes[i].attributes.shape;
  23.          parseArray.push({title:title,color:color});
  24.          
  25.      my_dg.dataProvider = parseArray
  26.      
  27.     }
  28. }
  29. var dgListener:Object = new Object();
  30. dgListener.cellPress = function() {
  31.     //var shape:Array = parseArray[i].shape;
  32.     var shape:Array = nodes.shape(this.firstChild, "shape"+i,i);
  33.     trace("shape is "+shape+" !");
  34.     //itemShape.text = this.nodes[i].shape;
  35. };
  36. // Add listener.
  37. my_dg.addEventListener("cellPress", dgListener);
  38. parseXML();



Here's my XML:
Code: [ Select ]
<?xml version="1.0" encoding="iso-8859-1"?>
<items>
 
  <item title="item1" color="black" shape="round"/>
  <item title="item2" color="blue" shape="square"/>
  <item title="item3" color="green" shape="triangle"/>
 
</items>
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <items>
  3.  
  4.   <item title="item1" color="black" shape="round"/>
  5.   <item title="item2" color="blue" shape="square"/>
  6.   <item title="item3" color="green" shape="triangle"/>
  7.  
  8. </items>



And here's where I'm having a problem:
Code: [ Select ]
trace("shape is "+shape+" !");




Any help is much appreciated!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

i wonder why is it called an array. because it use indexes?
then why you don't use any?
why you use node[i] but you don't use shape[i] ?

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 16 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.