[mtasc] XMLSockets, events, and -main

Andy Dwelly andy.dwelly at safedataco.com
Wed Sep 14 11:56:58 CEST 2005


I've made progress with this, thanks to comments here and in the 
archives. Francis' source code was particularly helpful.

As far as I can see the key to getting a useful call back to work is to 
use the Delegate class posted on the archives. I've dropped XMLSocket 
for plain old XML, here's a code fragment from the init method called 
from main....

      this.write("Canvas SWF deployed");    
      var xml = new XML();
      var announce = xml.createElement("announce");
      announce.attributes.username = "andy";
      xml.appendChild(announce);      
      this.write(xml);

      var xmlReply = new XML();
      xmlReply.onData = Delegate.create(this, onReply); //Key point
      xml.contentType = "text/xml";
      xml.sendAndLoad("/jalek/JAlekServlet", xmlReply);

My onReply method looks like this....

   function onReply(src) {
      this.write("The async src is " + src);
  }

and gets called when the data has arrived back from the server.

The delegate class was the one posted in the archives some time back:

class Delegate {
    private function Delegate () {};

    public static function create (scope, method:Function):Function {
        var params:Array = arguments.splice (2, arguments.length-2);
        var proxyFunc:Function = function ():Void {
            method.apply(scope, arguments.concat (params));
        }
        return proxyFunc;
    }
}

...I don't have enough AS yet to follow it precisely but I can see the 
broad outline of its operation. It does appear that

xmlReply.onData = onReply; simply does not work in 1.09. It seems to 
parse and the AS books I've read suggest that it should, but it doesn't 
in mtasc. I don't have access to mmc to confirm the point one way or the 
other. [Nicholas - if you want I could try and craft a minimal test case].

Andy






More information about the mtasc mailing list