User Guide
522 Using the External API
The External API’s XML format
Communication between ActionScript and an application hosting the Shockwave Flash
ActiveX control uses a specific XML format to encode function calls and values. In the
Introvert IM C# example, the ExternalInterfaceProxy class makes it possible for the code in
the application form to ignore this format and operate directly on the values. In order to
accomplish this, the ExternalInterfaceProxy class uses the methods of the
ExternalInterfaceSerializer class to actually translate the XML messages into .NET objects.
The ExternalInterfaceSerializer class has four public methods:
■ EncodeInvoke() Encodes a function name and a C# ArrayList of arguments into the
appropriate XML format.
■ EncodeResult() Encodes a result value into the appropriate XML format.
■ DecodeInvoke() Decodes a function call from ActionScript. The FlashCall event
object’s
request property is passed to the DecodeInvoke() method, and it translates the
call into an ExternalInterfaceCall object.
■ DecodeResult() Decodes the XML received as the result of calling an ActionScript
function.
There are two parts to the XML format used by the External API. One format is used to
represent function calls. Another format is used to represent individual values; this format is
used for parameters in functions as well as function return values. The XML format for
function calls is used for calls to and from ActionScript. For a function call from ActionScript,
Flash Player passes the XML to the container; for a call from the container, Flash Player
expects the container application to pass it an XML string in this format. The following XML
fragment shows an example XML-formatted function call:
<invoke name="functionName" returntype="xml">
<arguments>
... (individual argument values)
</arguments>
</invoke>
The root node is the <invoke> node. It has two attributes: name indicates the name of the
function to call, and
returntype is always xml. If the function call includes parameters, the
<invoke> node has a child <arguments> node, whose child nodes will be the parameter
values formatted using the individual value format explained next.