Both ActionScript and Java have object types for storing XML documents, and you can use Flash Remoting MX to send XML documents back and forth between ActionScript and Java.
In Flash, you can use an ActionScript XML object to represent and manipulate XML an document tree. In Java, you can use an org.w3c.dom.Document object to represent and manipulate an XML document tree. Flash Remoting MX converts ActionScript XML objects to org.w3c.dom.Document objects and org.w3c.dom.Document objects to ActionScript XML objects. For more information about ActionScript XML objects, see the Flash MX documentation set. For more information about the Java org.w3c.dom.Document interface, see the Java 2 Platform Standard Edition API documentation available at http://java.sun.com.
The following sections describe how you pass XML between ActionScript and Java.
Note: If you make a reference to an XML Document Type Definition (DTD) or schema in your XML document, you must use a Uniform Resource Identifier (URI) that the server can reach. Do not use a relative path.
The following ActionScript function creates an XML object and sends it as a parameter to a service function, which in this case is a JavaBean method that expects an org.w3c.dom.Document object; the first element of the XML document contains text entered in a Flash text field called input:
function testDocument()
{
xmlDocument = new XML();
firstElement = xmlDocument.createElement("TEST");
firstElement.attributes.message = input.text;
secondElement = xmlDocument.createElement("INSIDETEST");
firstElement.appendChild(secondElement);
xmlDocument.appendChild(firstElement);
flashtestService.testDocument(xmlDocument);
}
Note: You can also create an XML document object in ActionScript by passing a string representation of the XML to the new XML(source); constructor. For more information, see the Flash MX documentation set.
The JavaBean method discussed in the previous section returns an org.w3c.dom.Document object as follows:
public Document testDocument(Document doc)
{
return doc;
}
Flash Remoting MX converts the returned org.w3c.doc.Document object to an ActionScript result of type XML object, which can be used in a result handler function as follows:
function testDocument_Result(result)
{
output.text = result.firstChild.attributes["message"];
}
When the function above is called, the text contained in the first child element of the XML document root is displayed in a Flash dynamic text field called output. The text matches whatever text the user initially entered in the Flash text field called input.
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flashremoting/mx/Using_Flash_Remoting_MX/usingFRJ2EE10.htm
Comments
pavanathreya12 said on Jul 5, 2004 at 3:35 AM : No screen name said on Oct 2, 2005 at 11:24 PM :