WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Site Design > Flash Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Flash Discussion Forum Flash design presents a limitless number of possibilities for your sites and designs. Discuss your Flash ideas, questions and issues here.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-28-2004, 02:56 PM
sparkyfire sparkyfire is offline
WebProWorld New Member
 

Join Date: Jan 2004
Posts: 16
sparkyfire RepRank 0
Default Strange XML handling problem in flash

I posted this elsewhere and didn't get a responce so I thought I would try here. I've encountered a problem with my XML and getting flash to read it. I really need the first example to work, however it doesn't. The secound example works, but is not what I'm needing. I am using flash MX.

This doesn't work. Trace comes back undefined.

//=============Code===================
#include "XMLtoObject.as"

myXML = new XML()
myXML.ignoreWhite = true
myXML.load('celeb.xml');

myXML.onLoad = function(success) {
if (success) {
xo = this.toObject ();
trace(xo.lakewood.artistpic[1].attributes.jpegURL);
delete (myXML);
} else {
trace("XML file loading failed.");
}
};


//===============XML==================
<lakewood>
<artistpic jpegURL="lakewood/artist/jeremy.jpg"></artistpic>
<artistpic jpegURL="lakewood/artist/jeremy2.jpg"></artistpic>
</lakewood>

//=========END OF BAD EXAMPLE==========

I don't see a problem with the above code. So I test and can't find anything any deeper then 1 layer in xo. So I make the changes below and it works.

==============CODE====================

#include "XMLtoObject.as"

myXML = new XML()
myXML.ignoreWhite = true
myXML.load('celeb.xml');

myXML.onLoad = function(success) {
if (success) {
xo = this.toObject ();
trace(xo.artistpic[1].attributes.jpegURL);
delete (myXML);
} else {
trace("XML file loading failed.");
}
};

================XML======================
<artistpic jpegURL="lakewood/artist/jeremy.jpg"></artistpic>
<artistpic jpegURL="lakewood/artist/jeremy2.jpg"></artistpic>
=========================================

I need the ability to have deeper layers in my XML! Why can't I go deeper then 1 layer? What can I do to fix this?

Thank you,

Daniel
Reply With Quote
  #2 (permalink)  
Old 10-28-2004, 08:00 PM
sparkyfire sparkyfire is offline
WebProWorld New Member
 

Join Date: Jan 2004
Posts: 16
sparkyfire RepRank 0
Default

something I thought I would add. ok, xo is being populated by the include file. This file is below


================== start of XMLtoObject.as ==================

XML.prototype.toObject = function(input_xml)
{
if (input_xml == null) {
input_xml = this;
}
// make an empty object to attach properties and other objects to
var returnObj = new Object();
var tempObj = new Object();
// loop throught the child nodes of the returned xml...
for (var nodeIndex = 0; nodeIndex < input_xml.childNodes.length; nodeIndex++) {
var currentNode = input_xml.childNodes[nodeIndex];
// for text nodes.....
if (!(currentNode.firstChild.nodeValue == null && currentNode.hasChildNodes())) {
// anything thats not another nest of nodes, just make properties from them
// creating a String object lets us add properties to it later
var tempNode = new String(currentNode.firstChild.nodeValue);
if (returnObj[currentNode.nodeName] == null) {
returnObj[currentNode.nodeName] = tempNode;
// this is used for attaching attributes later
tempObj = returnObj[currentNode.nodeName];
} else {
// make an array if it doesn't exist already
if (returnObj[currentNode.nodeName][0] == null) {
var tempObj = returnObj[currentNode.nodeName];
returnObj[currentNode.nodeName] = new Array();
returnObj[currentNode.nodeName][0] = tempObj;
}
returnObj[currentNode.nodeName].push(tempNode);
// this is used for attaching attributes later
tempObj = returnObj[currentNode.nodeName][returnObj[currentNode.nodeName].length - 1];
} } else {
// this is another nested object....
// if an object of this name doesnt exists...
if (returnObj[currentNode.nodeName] == null) {
returnObj[currentNode.nodeName] = this.toObject(currentNode);
// this is used for attaching attributes later
tempObj = returnObj[currentNode.nodeName];
} else {
// make an array if it doesn't exist already
if (returnObj[currentNode.nodeName][0] == null) {
var tempObj = returnObj[currentNode.nodeName];
returnObj[currentNode.nodeName] = new Array();
returnObj[currentNode.nodeName][0] = tempObj;
}
returnObj[currentNode.nodeName].push(this.toObject(currentNode));
// this is used for attaching attributes later
tempObj = returnObj[currentNode.nodeName][returnObj[currentNode.nodeName].length - 1];
} }
tempObj.attributes = new Object();
var attributeCounter = 0;
for (var a in currentNode.attributes) {
attributeCounter++
tempObj.attributes[a] = currentNode.attributes[a];
}
if (attributeCounter == 0) {
tempObj.attributes = null;
}
}
// return the new object
return returnObj;
}

============== end of XMLtoObject.as ======================


Thanks for all your help with this!

Daniel
Reply With Quote
  #3 (permalink)  
Old 10-30-2004, 06:07 PM
sparkyfire sparkyfire is offline
WebProWorld New Member
 

Join Date: Jan 2004
Posts: 16
sparkyfire RepRank 0
Default

something I thought about that might help. When I call my xml document in, I can view all the contents of the xml document. It seems as though theres something going on with my include file. But its been checked and is a known working AS. If anyone has any thoughts on anything, some wild crazy thought, I'm desperate...I'll try just about anything! Theres always revert. :)

Thanks

Daniel
Reply With Quote
  #4 (permalink)  
Old 10-30-2004, 06:50 PM
sparkyfire sparkyfire is offline
WebProWorld New Member
 

Join Date: Jan 2004
Posts: 16
sparkyfire RepRank 0
Default

here is a link to all the files used here. If you wanna check it out and see if you can find anything. This is only what you would need. There are 2 .fla's, they are test1 for the first test above and test2 for the secound test above. They each have thier own text files and use the same .as. If anyone can find anything, even that its working ok on thier computer if they try it, please let me know.

Thanks for everyones help with this problem.

Daniel

http://wpwd.net/flash/help/problem.zip
Reply With Quote
Reply

  WebProWorld > Site Design > Flash Discussion Forum
Tags: flash, handling, problem, strange, xml



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Search Engine Friendly URLs by vBSEO 3.0.0