A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [F6!!!] Array w. XML issue

  1. #1
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693

    [F6!!!] Array w. XML issue

    i'm not sure if this is a problem with the version of Flash(Flash 6) I'm using or just poor coding... but check out what the values are returning... it seems I cannot differentiate between myArray[0] and myArray[1] once [1] is assigned [0] gets all the attributes of [1]... please someone help me! here is the code:
    Code:
    //declare our xml object
    myXML = new XML();
    //ignore any whitespace found 
    myXML.ignoreWhite = true;
    var temp = new Object();
    var myArray = new Array;
    //setup an event to track the data coming in
    myXML.onLoad = function(success) {
    //data loaded....lets begin
    
    for (var i=0; i<this.firstChild.childNodes.length; i++) {
    temp.Title=this.firstChild.childNodes[i].childNodes[0].childNodes[0].nodeValue;
    temp.Body=this.firstChild.childNodes[i].childNodes[1].childNodes[0].nodeValue;
    temp.Keywords=this.firstChild.childNodes[i].childNodes[2].childNodes[0].nodeValue;
    myArray[i]=temp;
    
    }
    };
    
    myXML.load("samples.xml");
    
    function displayMember(){
    
    txtTitle.text=myArray[0].Title; 
    txtBody.text=myArray[0].Body
    txtKeywords.text=myArray[0].Keywords;
    }
    
    btnNext.onPress=function(){
    	displayMember();
    	trace(myArray[0].Title + " and " + myArray[1].Title);
    // RETURNS:Sample Practice Two and Sample Practice Two
    	//
    	temp.Title="test title";
    	temp.Body="test body";
    	trace(myArray[0].Body + " and " + myArray[2].Body);
    //RETURNS: test body and 
    	myArray[2]=temp;
    //RETURNS: test body and test body
    trace(myArray[0].Body + " and " + myArray[2].Body);
    }
    stop();
    edit: here is the xml incase it will help understand:

    Code:
    <samples>
    
    <sample>
    <title>Sample Practice One</title>
    <body>Fox in the whole went round and round!</body>
    <keywords>corporate espionage, privacy, hr</keywords>
    </sample>
    
    
    <sample>
    <title>Sample Practice Two</title>
    <body>Dog jumped over the merry fox!</body>
    <keywords>privacy, hr, laptops</keywords>
    </sample>
    
    </samples>
    if i'm missing any info needed to help, just let me know... Thanks in advance,

    ChaseNYC
    mmm signature

  2. #2
    Member
    Join Date
    Sep 2002
    Location
    Seattle
    Posts
    93
    Move where you define 'temp' like to in the loop:
    for (var i=0, temp=new Object(); i<this.firstChild.childNodes.length; i++) {
    ...

    gsb

  3. #3
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    Code:
    myXML = new XML();
    myXML.ignoreWhite = true;
    myXML.load("samples.xml");
    var myArray = new Array;
    
    myXML.onLoad = function(){
    for (var i=0; i<this.firstChild.childNodes.length; i++){
    temp = new Object();
    aNode = this.firstChild.childNodes[i];
    temp.Title = aNode.childNodes[0].childNodes[0].nodeValue;
    temp.Body = aNode.childNodes[1].childNodes[0].nodeValue;
    temp.Keywords = aNode.childNodes[2].childNodes[0].nodeValue;
    myArray[i] = temp;
    }
    };
    
    // List Variables shows --
    
    /*
    _level0.myArray = [object #2, class 'Array'] [
        0:[object #3, class 'Object'] {
          Title:"Sample Practice One",
          Body:"Fox in the whole went round and round!",
          Keywords:"corporate espionage, privacy, hr"
        },
        1:[object #4, class 'Object'] {
          Title:"Sample Practice Two",
          Body:"Dog jumped over the merry fox!",
          Keywords:"privacy, hr, laptops"
        }
      ]
    */

  4. #4
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693
    thank you kind sirs...
    mmm signature

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