TwelvestoneFlash

Receiving XML in Flash


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
X-DUD!!!11~~
 
2007-12-18

Yeah hi!

I have a little Flash movie that successfully sends parsed XML to an ASP script.

The script then returns the following:

<?xml version=""1.0""?> 0 If I have a dynamic text field named "returnCode" will the value simply display by itself, or do I have to do something?

Thanks k

Hideaway
 
2007-12-18

If I'm not mistaken, you need to load the response, then parse it and set the "text" of the field to the value of the returnCode node.

DontBogartMe
 
2007-12-18

Originally posted by: Hideaway If I'm not mistaken, you need to load the response, then parse it and set the "text" of the field to the value of the returnCode node.

yep, that's about the size of it.

X-DUD!!!11~~
 
2007-12-19

Yabbut

Load what? From memory? Here's where I get confused, 'cause it's not actually generating a page or XML document, just doing the equivalent of PHP's "print."

sorry i'm an omgwtfn00blol

scudsucker
 
2007-12-19

Using the XML.sendAndLoad method...

var s = "xml"; var sendXML = new XML(s); var loadXML = new XML(); loadXML.ignoreWhite = true; loadXML.onLoad = function(ok) { if (ok) { trace(this.firstChild.childNodes[0].nodeValue); } else { trace("failed to load the XML response"); } }; sendXML.sendAndLoad("http://www.xdud.com/data.asp", loadXML);

mystic_juju
 
2007-12-19

Greensock has a nice AS2 xml parser:

HOT XXX SQUID PORN

X-DUD!!!11~~
 
2007-12-19

Well, the data's already been sent (verifiedly) using loadVariablesNum();

I'd just like to add a thing to the Flash movie that tells the user information was submitted successfully.

Would I just delete the "send" lines from the above script? :oof:

DontBogartMe
 
2007-12-19

Originally posted by: X-DUD!!!11~~ using loadVariablesNum();

dump that shit and go with scud's code.

The idea is that your Flash script creates a string containing the XML data you want to send back to the ASP script on the server. The ASP script gets that XML, parses it, does it's thang, then the ASP writes some XML back like you described (instead of writing the usual HTML, it's now writing XML). Now because you've used the sendAndLoad method in your Flash, that ASP spewed XML will be read back into your Flash, and you can parse it and deal with it in the onLoad function.

Laaahvely.

P.S. you don't send 'parsed XML' - you send valid XML and parse XML that you've received. Just saying.

persist
 
2007-12-19

you can apply the xml directly using the xml tags with the css object.

if you so wanted.

Fir zample:

throw this in your dynamic, html enabled field:

** <?xml version=""1.0""?>

 <result>

      <returnCode>0</returnCode>

 </result>

**

Then using a css object: ** result {

color:#000099;

}

**

X-DUD!!!11~~
 
2007-12-19

Okay, well, I might as well post the full script just to be sure.

var xml:XML = new XML(); xml.parseXML("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); loadVariablesNum("OMGTOPDSEKRATURL.asp", "0", "POST");

Is this not submitting parsed XML?

noob++;

scudsucker
 
2007-12-20

I actually like the simplicity of Persist's method for display.

var xml:XML = new XML();

xml.parseXML("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");

is equivalent to

var xml:XML = new XML("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");

so

var s = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"; //------------------------------------------------------------------------- var sendXML = new XML(s); var loadXML = new XML(); loadXML.ignoreWhite = true; loadXML.onLoad = function(ok) { if (ok) { trace(this.firstChild.childNodes[0].nodeValue); // Using persists's method to display..... myDynamicHtmlTextField.html=true; myDynamicHtmlTextField.htmlText=this.toString(); } else { trace("failed to load the XML response"); } }; sendXML.sendAndLoad("OMGTOPDSEKRATURL.asp", loadXML);

DontBogartMe
 
2007-12-20

personally I find that loadVariablesNum method very hard to understand - because it mysteriously sends that xml object in the POST variables, but you don't explicitly have to tell it to do so. And it also populates some equally mysterious variables in your SWF. And to cap it all it uses levels. Levels are teh devil.

Really, dump it and go with scud's method - it's much easier to understand (once you are familiar with that new syntax of course).

So your code might look something like this:

var s = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"; var sendXML = new XML(s); var loadXML = new XML(); loadXML.ignoreWhite = true; loadXML.onLoad = function(success:Boolean) { // Process the response from the server.

if (success) {
    trace("This is the XML I got from the server: \n" + this);

    // This code runs when the ASP script properly sends back a response - even if that response is to say it failed.

    // Parse the XML that the ASP script has sent:
    if(this.firstChild.nodeName == "result"){
        if(this.firstChild.firstChild.nodeName == "returnCode"){
            // Set the textfield to show that return parameter.
            returnCode.text = this.firstChild.firstChild.firstChild.nodeValue;
        }else{
            // Node wasn't called "returnCode"
            trace("Node wasn't called 'returnCode', it was: " + this.firstChild.firstChild.nodeName);
        }
    }else{
        // Node wasn't called "result"
        trace("Node wasn't called 'result', it was: " + this.firstChild.nodeName);
    }
} else {
    // This code runs when the ASP script fails to return, e.g. a 404 error or some network error.
    trace("failed to load the XML response");
}

};

sendXML.sendAndLoad("OMGTOPDSEKRATURL.asp", loadXML);

To test it locally, make a plain text file, paste in that XML you had at the top of this thread, and call it, say, "test_sendandload.xml". Stick it in the same folder where you have your FLA. Then change that sendAndLoad line to this:

sendXML.sendAndLoad("test_sendandload.xml", loadXML);

Note: This looks odd, like there's a firstChild too many in there, but it is right: returnCode.text = this.firstChild.firstChild.firstChild.nodeValue; It's because the '0' text is a child node of the node.

I've just tested this myself locally (without bothering to use ASP), and it works fine.

You may find you have trouble with targetting the returnCode textfield, that will depend on how your Flash is built. I just slapped it on the stage.

DontBogartMe
 
2007-12-20

oh I went to town a little bit with all those if-elses and the traces of the nodeNames, but I put all that in to hopefully help you follow the logic of what was going on.

Also note there was an error in the XML you quoted - too many " in the <?xml?> tag - <?xml version="1.0"?> 0

X-DUD!!!11~~
 
2007-12-20

The above is what the guy said the ASP script would send back after it received data. I have no idea how easy it would be for him to change it.

I can't really test this stuff on my own machine, it needs to integrate with a system that's already built and being depended on greatly.

I also noticed the new scripts don't use parseXML; is it deprecated? The reason I used it was because it was sending those horrible %20 %50 %80 etc characters rather than the readable ones. Whatever the technical term for that is. ;P

DontBogartMe
 
2007-12-20

locally you can't test it with proper active data, but you can test that the interface receives and parses the XML correctly by creating text XML files that contain XML in the same format as you expect the server to produce - then just change the URLs in your SendAndLoad calls (or loadVariablesNum if you insist) to those test XML files. It's worth doing that - it'll speed up your development no end.

If your man said that's the XML to expect, then so be it. I imagine those doubled-up quotes are just an encoding typo, copy and pasted from some nasty ASP code or something. And that in the live version, the quotes will be correct. I wouldn't worry about it unless you start getting errors.

Dunno about parseXML - maybe it does some encoding (that's the word you were looking for I think), I dunno, you'll have to RTFM on that one.

Did your video player have a full screen option? If so, please have a look at my thread?

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

Receiving XML in Flash