140
Chapter 7: Using Flash Remoting for Java
The following example shows entries for the FlashRole role and corresponding EJB method
permissions in an ejb-jar.xml file:
<assembly-descriptor>
<security-role>
<role-name>FlashRole</role-name>
</security-role>
<method-permission>
<role-name>FlashRole</role-name>
<method>
<ejb-name>SampleLoanBean</ejb-name>
<method-name>calculate</method-name>
</method>
</method-permission>
</assembly-descriptor>
Passing XML objects between Flash and Java
Both ActionScript and Java have object types for storing XML documents, and you can use Flash
Remoting to send XML documents back and forth between ActionScript and Java.
In Flash, you can use an ActionScript XML object to represent and manipulate an XML
document tree. In Java, you can use an org.w3c.dom.Document object to represent and
manipulate an XML document tree. Flash Remoting 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 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.
Sending an ActionScript XML object to Java
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()
{
var xmlDocument:XML = new XML();
var firstElement:XMLNode = xmlDocument.createElement("test");
firstElement.attributes.message = input.text;
var secondElement:XMLNode = xmlDocument.createElement("insidetest");
firstElement.appendChild(secondElement);
xmlDocument.appendChild(firstElement);