Hi Peter,

I'm not sure this is what you are looking for, but I have used this approach several times and it works great for me.

I usually connect flash to PHP, but it should be the same way for JSP.

This is PHP code. Have your JSP process whatever it has to process in order to get the data. The write the data as if you were outputing a regular XML file, but in this case not to a file, but just output with prints or something similar (I don't know JSP).

$xml ='<?xml version="1.0" encoding="UTF-8"?>'."\n";
$xml.='<data>'."\n";
$xml.='<item id="1">This is text inside item 1</item>'."\n";
$xml.='<item id="2">This is text inside item 2</item>'."\n";
$xml.='<item id="3"><![CDATA[<b>This is HTML inside item 3, inside CDATA so it won't get parsed</b>]]></item>'."\n";
$xml.='</data>'."\n";
header("Content-type: text/xml; charset=UTF-8");
echo utf8_encode($xml);


Inside flash I use a trick I found. We can use a LoadVars object to make the request to the server, sending info through POST or GET, and have it load directly into a XML object.

_global.dynamicLoadedXml = new XML();
_global.dynamicLoadedXml.ignoreWhite = true;
_global.dynamicLoadedXml.onLoad = function(success){
//This code is executed once the load is complete. In other words once your JSP file is processed and returns a code similar to the above.
   if(sucess){
//the file was successfully loaded. Do whatever you need in terms of parsing.
       var root:XMLNode = this.firstChild;
      _global.dataArray = new Array();

       for(var i:Number = 0; i<root.childNodes.length; i++){
           var node:XMLNode = root.childNodes[i];
           _global.dataArray[i] = node.attributes.id;
      }
   }else{
      //the file was not successfully loaded. Send error feedback to user.
   }
}

//these are the vars you are going to send through POST
_global.varsToUseByJSP = new LoadVars();
_global.varsToUseByJSP.id = valueToSend; //whatever value you want to send to JSP through POST

//use this to avoid cache problems loading the XML
var rnd = Math.round(Math.random()*10000);
var urlToGo = "http://www.xpto.com/process.php?rnd="; + rnd;

_global.varsToUseByJSP.sendAndLoad(urlToGo, _global.dynamicLoadedXml, "POST");



Good Luck!  :-)

Telmo Dias


Maziak, Peter wrote:
I have a flash app that gets populated by parsing data from an external
XML file.  However, my JSP development team tells me that to keep the
XML in a session it would be better to load the XML as a string from the
HTML (JSP).  Is it possible to put the XML into a hidden input field
within a form on the containing HTML?  How easy is it to have Flash
communicate with the HTML and vice-versa?  Or is there a better approach
to get the XML in and out of Flash (other than an external file)?
Also, I've looked into the Flash/JavaScript Integration Kit [
http://osflash.org/doku.php?id=flashjs OR
http://weblogs.macromedia.com/flashjavascript/ ] but am confused by the
installation instruction:

        Copy the following library files from source/flash/actionscript
into your Flash Authoring classpath:
        com/macromedia/javascript/JavaScriptProxy.as
        com/macromedia/javascript/JavaScriptSerializer.as

Where is the Flash Authoring classpath!?
Thanks,
-Pete
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com



_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to