|
-
Flash Incompetent
[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
-
Move where you define 'temp' like to in the loop:
for (var i=0, temp=new Object(); i<this.firstChild.childNodes.length; i++) {
...
gsb
-
FK'n_dog
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"
}
]
*/
-
Flash Incompetent
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|