PDA

View Full Version : Questions about XML and Flash


Pino_Chan
10-13-2008, 09:55 AM
I'm working on some Flash programming, and well, I'm in the noob section for a reason. Here's what I'm working at:

If you have an XML file with data, how do you load that XML file into a Flash site so it displays that data?

Then, say there are two different versions of the same file, "file1_x" and "file1_y", and you want to load one or the other depending on a condition. How do you get it to default one or the other? Basically, I'm dealing with programming conditionals and defaults in Flash, which I don't understand enough about (yet!).

Any suggestions?

Thanks in advance!

edenmills
10-13-2008, 11:34 PM
My question is, Last night I visited YouTube website and I’m having trouble with flash player software. Whenever I maximize the Youtube video, my system is creating problem for me and hangs. Please help me.

Crystal Meth (http://www.crystalrecovery.com)

Nabren
10-14-2008, 05:40 PM
I'm working on some Flash programming, and well, I'm in the noob section for a reason. Here's what I'm working at:

If you have an XML file with data, how do you load that XML file into a Flash site so it displays that data?

Then, say there are two different versions of the same file, "file1_x" and "file1_y", and you want to load one or the other depending on a condition. How do you get it to default one or the other? Basically, I'm dealing with programming conditionals and defaults in Flash, which I don't understand enough about (yet!).

Any suggestions?

Thanks in advance!

Okay, basically you are going to want something to the tune of:


var request:URLRequest = new URLRequest("xmlfile.xml");
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);

try
{
loader.load(rq);
} catch (error:Error) {
trace("Unable to load XML file");
}

function loadXML(e:Event) {
var xmlData:XML = new XML(e.target.data);
}


You can then access any node in the XML. So basically say an XML file:


<root>
<SomeNode>150</SomeNode>
<MultiNode><Value>200</Value></MultiNode>
<MultiNode><Value>200</Value></MultiNode>
</root>


You would go:


var someNode = xmlData.someNode; // to get the single node
//or
for each(var multiNode:XML in xmlData.MultiNode) {
var theValue = multiNode.Value;
}


Please note I named my vars after the nodes but you don't have to do that.

So your whole thing would be, for instance:


var request:URLRequest = new URLRequest("xmlfile.xml");
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);

try
{
loader.load(rq);
} catch (error:Error) {
trace("Unable to load XML file");
}

function loadXML(e:Event) {
var xmlData:XML = new XML(e.target.data);

var someNode = xmlData.someNode; // to get the single node
trace("someNode = " + someNode);
//or
for each(var multiNode:XML in xmlData.MultiNode) {
var theValue = multiNode.Value;
trace("multiNode value = " + theValue);
}
}