Flash Platform // Actionscript // FDT // Pixlib - Mot-clé - pixSWXEspace rassemblant différentes informations liées à la Flash plateforme d'Adobe, l'Open Screen Project, FDT de Powerflasher et l'excellent framework Actionscript Pixlib2015-01-12T10:03:24+01:00Laurent Deketelaereurn:md5:dc39f1be241e0e0f27311e2a6df9ed38Dotclear[pixSWX] - Une alternative au remotingurn:md5:b230e3740b0503a8a38f4c8975a69b6d2007-10-24T17:18:00+02:002008-01-10T23:16:08+01:00Laurent DeketelaereFlash plateformeActionscriptPixlibpixSWXremotingswxSWXformat<p><a href="http://code.google.com/p/pixswx/wiki/First_explanation">english version</a> translated by Gilles Bertand</p>
<p>Salut <img src="/themes/default/smilies/smile.png" alt=":)" class="smiley" /><br /></p>
<p>Tout d'abord pour les personnes qui ignore ce qu'est SWXformat une petite video s'impose :</p>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="370" id="viddler"><param name="movie" value="http://www.viddler.com/player/ad098fea/" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /></object>
<p>[MAJ] - Pour la version Française : <a href="http://www.beflash.be/?p=35" hreflang="fr">beflash.be</a></p>
<p>Maintenant que tout le monde sait ce qu'est SWXformat, voyons ce qu'est pixSWX. :p<br /></p>
<p>C'est tout simplement l'API qui permet d'utiliser SWX dans pixLib. <img src="/themes/default/smilies/smile.png" alt=":)" class="smiley" /><br /></p> <h3>SWXCall</h3>
<p>Il s'agit de la classe principal, c'est elle qui va envoyer et recevoir les informations.</p>
<pre>
[actionscript]
// -- Basic usage
var swx : SWXCall = new SWXCall("http://www.geturl.net/services/swx_php_1/php/swx.php", "Simple.addNumbers");
swx.addListener(this); // implements ISWXListener
swx.load(18, 32);
</pre>
<p><br /></p>
<h3>ISWXListener</h3>
<p>Est une interface déclare l'ensemble des méthodes qu'un écouteur doit implémenter.</p>
<pre>
[actionscript]
public function onFault(e : SWXFaultEvent) : Void;
public function onResult(e : SWXResultEvent) : Void;
// extends ILibListener
public function onLoadInit(e:LibEvent) : Void;
public function onLoadProgress(e:LibEvent) : Void;
public function onTimeOut(e:LibEvent) : Void;
</pre>
<p><br /></p>
<h3>SWXResponder</h3>
<p>Cette classe permet de définir où l'on soit récupérer la réponse du serveur, basé sur la même logique qu'un Delegate.</p>
<pre>
[actionscript]
var swx : SWXCall = new SWXCall("http://www.geturl.net/services/swx_php_1/php/swx.php", "Simple.addNumbers");
var swxResponder : SWXResponder = new SWXResponder(this, onResult, onFault, onProgress);
swx.addListener(swxResponder);
swx.load(18, 32);
</pre>
<p><br /></p>
<p>Dans cette exemple, ce sont les méthodes onResult, onFault, onProgress déclarer sur this qui seront utilisé.</p>
<h3>SWXProxy</h3>
<p>Cette classe permet de regrouper l'ensemble des méthodes d'un service.</p>
<pre>
[actionscript]
class pixswx_first.net.SWXSimpleService
extends SWXProxy
{
public static var echoDataMETHOD : SWXMethod = new SWXMethod("echoData");
public static var addNumbersMETHOD : SWXMethod = new SWXMethod("addNumbers");
public function SWXSimpleService( sURL : String, serviceName : String )
{
super(sURL, serviceName);
}
public function echoData( swxlistener : ISWXListener, o ) : Void
{
super.callMethod(echoDataMETHOD, swxlistener, o);
}
public function addNumbers( swxlistener : ISWXListener, nFirst : Number, nSecond : Number ) : Void
{
super.callMethod(addNumbersMETHOD, swxlistener, nFirst, nSecond);
}
}
</pre>
<p><br /></p>
<pre>
[actionscript]
// -- SWXProxy Usage
var sGateway : String = "http://www.geturl.net/services/swx_php_1/php/swx.php";
var swxService : SWXSimpleService = new SWXSimpleService(sGateway, "Simple");
swxService.addNumbers(swxResponder, 100, 31);
</pre>
<p><br /></p>
<h3>SWXProxyLocator</h3>
<p>Il s'agit d'une map qui permet de récupérer de façon global les différents service d'une application, basé sur le fonctionnement du FrontController -> http://blog.geturl.net/post/2006/10/27/63-pixlib-vues-modeles-controleur .</p>
<pre>
[actionscript]
class pixswx_first.net.SWXLocator
extends SWXProxyLocator
{
private static var _oI : SWXLocator;
public static var simpleSERVICE : String = "Simple";
public static function getInstance() : SWXLocator
{
if (!_oI) _oI = new SWXLocator();
return _oI;
}
private function SWXLocator()
{
super();
}
public function init( remotingURL : String ) : Void
{
gatewayURL = remotingURL;
Debug.INFO(toString() + " initialization with '" + gatewayURL + "' gateway url.");
push(simpleSERVICE, new SWXSimpleService(gatewayURL, simpleSERVICE));
// push all services
}
}
</pre>
<p><br /></p>
<p>à l'initialisation du site :</p>
<pre>
[actionscript]
SWXLocator.getInstance().init("http://www.geturl.net/services/swx_php_1/php/swx.php");
</pre>
<p><br /></p>
<p>Ensuite :</p>
<pre>
[actionscript]
var swxService : SWXSimpleService = SWXSimpleService(SWXLocator.getInstance().getService(SWXLocator.simpleSERVICE));
swxService.echoData(new SWXResponder(this, onSWXResult, onSWXFault), "Hello World!");
</pre>
<p><br /></p>
<p>Voilà pour ce tour d'horizon. <br /></p>
<p>Je me suis très largement inspiré de l'API remoting que Francis a écrit, donc ce que j'ai écris au dessus est valable à peut de chose près pour les services en remoting (AMFPHP par exemple).</p>
<p><strong>+ infos :</strong><br /></p>
<ul>
<li><a href="http://code.google.com/p/pixswx/" hreflang="fr">Les sources de pixSWX</a></li>
<li><a href="http://code.google.com/p/pixswx/downloads/list" hreflang="fr">Les sources des exemples</a></li>
<li><a href="http://www.swxformat.org" hreflang="fr">SWXformat</a></li>
<li><a href="http://www.pixlib.org" hreflang="fr">pixLib</a></li>
</ul>
<p>bye, <br /></p>
<p>Laurent <img src="/themes/default/smilies/smile.png" alt=":)" class="smiley" /></p>