<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type"
content="text/html; charset=ISO-8859-1">
<title>AMF::Perl - Flash Remoting in Perl</title>
<style>
body {
scrollbar-3d-light-color: #000000;
scrollbar-arrow-color: #000066;
scrollbar-base-color: #003366;
scrollbar-dark-shadow-color: #FFFFFF;
scrollbar-face-color: #003366;
scrollbar-highlight-color: #FFFFFF;
scrollbar-shadow-color: #000000;
color: #000000;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 12px;
margin: 0px;
}
span.text {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 12px;
color: #003366;
}
span.red {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #990000;
}
div.notes {
background: #dddddd;
font-family: Verdana, Arial, helvetica, sans-serif;
font-size: 12px;
margin-left: 10px;
margin-right: 10px;
padding: 5px;
border-color: #000000;
}
div.tableSub {
background: #CCCCFF;
font-family: Verdana, Arial, helvetica, sans-serif;
font-size: 13px;
color: #003366;
margin-left: 0px;
margin-right: 0px;
padding: 2px;
border-color: #000099;
border-size: 2px;
}
pre {
color: #3366CC;
margin-left: 40px;
margin-right: 40px;
padding: 10px;
font-size: 12px;
}
P {
font-family: Verdana, Arial, helvetica, sans-serif;
font-size: 11px;
color: #000000;
}
A:link { color: #3366AA; text-decoration: none; }
A:visited { color: #3366CC; text-decoration: none; }
A:active { color: #00CC99; text-decoration: none; }
A:hover { color: #FFFFFF; text-decoration: none; background-color: #6699CC; }
A.noDec:link { color: #000099; font-weight: bold; text-decoration: none; }
A.noDec:visited { color: #000099; font-weight: bold; text-decoration: none; }
A.noDec:active { color: #000099; font-weight: bold; text-decoration: none; }
A.noDec:hover { color: #3366AA; font-weight: bold; text-decoration: underline; background-color: transparent; }
A.plain:link { color: #000033; text-decoration: none; }
A.plain:visited { color: #000033; text-decoration: none; }
A.plain:active { color: #000033; text-decoration: none; }
A.plain:hover { color: #3366AA; text-decoration: none; background-color: transparent; }
h2 {
color: #333333;
font-size: 20 px;
font-weight: bold;
}
h3 {
color: #333333;
font-size: 18 px;
font-weight: bold;
}
h4 {
color: #0066CC;
font-size: 14px;
font-weight: bold;
}
</style>
</head>
<body
style="background-image: url(orn5.gif);">
<div style="position: absolute; left: 20px;">
<h1>AMF::Perl - Flash Remoting in Perl<br>
</h1>
<table cellpadding="2" cellspacing="2" border="0"
style="text-align: left; width: 600px;">
<tbody>
<tr>
<td style="vertical-align: top;"><big><span
style="font-weight: bold;">To use AMF::Perl, download it
and install in the usual way (perl Makefile.PL; make; make install).<br><br>
To build/export .swf files with "Flash Remoting" you need to install
<a href=http://www.macromedia.com/software/flashremoting/downloads/components/>
Flash Remoting MX Components </a> (free download).
This will install the files "NetServices.as" and "NetDebug.as" that are
used in the ActionScript.
</span></big><br>
<hr style="width: 100%; height: 2px;"><big><span
style="font-weight: bold;"></span></big>
<h2>Sample code that uses Flash Remoting <br>
</h2>
(See also examples that are distributed with the module).
<br>
<a href=encoding.html>Read this</a> if you want to send and receive strings in non-English encodings.
<br><br>
Client code:<br>
<br>
<pre>//Obligatory includes<br>#include "NetServices.as"<br>#include "NetDebug.as"<br><br>//Get a connection object<br>NetServices.setDefaultGatewayURL("http://host/cpu.pl");<br>connection = NetServices.createGatewayConnection();<br><br>//Get a pointer to a service<br>remoteService = connection.getService("Foo", this);<br><br>//Call a remote method on that service<br>remoteService.bar();<br><br>//or... send arguments to the server:<br>remoteService.bar(arg1, arg2);<br><br>//This callback function will be invoked<br>function bar_result(value)<br>{<br> //do something with the value<br>}<br></pre>
<br>
<big> Server code, option A - service registration.</big><br>
Use in simple applications.<br>
<pre>
use AMF::Perl;<br><br>package Foo;<br><br>sub new<br>{<br> my ($proto)=@_;<br> my $self={};<br> bless $self, $proto;<br> return $self;<br>}<br><br>sub bar<br>{<br> my ($self, $arg1, $arg2) = @_;<br> my $value;<br><br> #Compute a return value<br> #...<br><br> return $value;<br>}<br><br>#Create the gateway object<br>my $gateway = AMF::Perl->new; <br><br>#Register a service that provides methods.<br>#You can register more than one service.<br>#This can happen during server startup (if running under mod_perl).<br>$gateway->registerService("Foo",new Foo());<br><br>#Let the gateway figure out who will be called.<br>$gateway->service();<br> <br></pre>
<big> Server code, option B - limited service discovery.</big><br>
Use in complex applications.<br>
<br>
Part 1. The gateway script.<br>
<br>
<pre>use AMF::Perl;<br><br><br>#Create the gateway object<br><br>my $gateway = AMF::Perl->new; <br><br>#Set a directory that will contain Perl package.<br>#Each package will correspond to one service -<br>#there can be as many as you want!<br>#You can set only one class path, though.<br><br>$gateway->setBaseClassPath("./basicservices/");<br><br>#Let the gateway figure out who will be called.<br><br>$gateway->service();<br><br><br></pre>
<span style="font-weight: bold;"></span><br>
Part 2. Sample class in the registered directory.
<pre><br>package DataEcho;<br><br>sub new<br>{<br> my ($proto)=@_;<br> my $self={};<br> bless $self, $proto;<br> return $self;<br>}<br><br><br>sub methodTable<br>{<br> return {<br> "echoNormal" => {<br> "description" => "Echoes the passed argument back to Flash (no need to set the return t<br>ype)",<br> "access" => "remote", # available values are private, public, remote<br> },<br> "echoDate" => {<br> "description" => "Echoes a Flash Date Object (the returnType needs setting)",<br> "access" => "remote", # available values are private, public, remote<br> "returns" => "date"<br> },<br> "echoXML" => {<br> "description" => "Echoes a Flash XML Object (the returnType needs setting)",<br> "access" => "private", # available values are private, public, remote<br> "returns" => "xml"<br> }<br> };<br>}<br><br>sub echoNormal<br>{<br> my ($self, $data) = @_;<br> return $data;<br>}<br>sub echoDate<br>{<br> my ($self, $data) = @_;<br> return $data;<br>}<br>sub echoXML<br>{<br> my ($self, $data) = @_;<br> return $data;<br>}<br><br>1;<br><br></pre>
</td>
</tr>
</tbody>
</table>
</div>
<br>
</body>
</html>