-
XML into flash?!
I´ve previously worked with variables loaded into flash by having a string returned to me when I load an asp-page (loadVariables), and then used that variable within flash. Now our "coders" have made a webservice that I send parameters into and then get a XML-aswer back...loaded into a movieclip in my movie.
How do I use this answer?! Below I have an example of it:
<?xml version="1.0" encoding="utf-8" ?>
<boolean xmlns="http://www.infracontrol.com/">false</boolean>
I want to use that "false" but I don´t know how to get it out of the string, ´cause it´s not a variable with a value in it?!
Please help me!
Can I use the XML-object to "extract" the answer sent to me? Or put it in a variable on "my side", within flash?!
-
Hi tobiasniva,
First off, when showing XML in these forums, wrap it in [php] and [/php] so that it shows up like this:
PHP Code:
<boolean xmlns="http://www.infracontrol.com/">false</boolean>
Next, you need to load your document into an XML object, like this:
code:
var xmlDoc = new XML();
xmlDoc.ignoreWhite = true;
xmlDoc.onLoad = parseXML;
// this will depend on how you access your Web Service
xmlDoc.load( '/WebService.asmx' );
function parseXML( success )
{
if( success )
{
// XML loaded and parsed OK
// now we can get the value...
// this = the XML document
// this.firstChild = your root element (<boolean />)
// this.firstChild.firstChild = the text element
// this.firstChild.firstChild.nodeValue = the text value of the text element
trace( this.firstChild.firstChild.nodeValue );
// of course, you would probably set a variable, eg:
_root.blnTestResult = (this.firstChild.firstChild.nodeValue == 'true');
// note that inside this function we have to use absolute paths
// to variables etc, thus the _root. prefix
}
else
{
// XML failed to load
_root.gotoAndPlay( 2 );
// of course you should use a frame number that corresponds to
// a nice error display, or do something simmilar
}
}
Hope this helps!
Tim Walters
Senior Developer
XML Evangelist
"XML isn't a language, it's a way of life!"
-
thanx...
One more question though...
I see that you´ve used XML.load. I know that this checks if the XML is loaded correctly...but is it then necessary to use if (XML.loaded == true) { myFunction } to be sure that the whole XML is loaded!?! Or is this "overkill"?
Grateful for tips...
-
Re: thanx...
Originally posted by tobiasniva
One more question though...
I see that you´ve used XML.load. I know that this checks if the XML is loaded correctly...but is it then necessary to use if (XML.loaded == true) { myFunction } to be sure that the whole XML is loaded!?! Or is this "overkill"?
Grateful for tips...
well no, another way of doing it would be:
PHP Code:
onload = parseXML;
this will immediately call the parseXML function as soon as the data has been loaded. Its also a better way of doing things.
:/
kevin.beckett@future8.co.uk
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
|