Using Macromedia's AS1 Flash Remoting with Forms/AS2 in Flash MX 2004 Professional

There was a post on Flashcoders today by Craig Earls, wherein he states "I am having a very difficult time getting remoting to work in an AS 2.0 class."

Brian LeRoux responded that "it's because MM doesn't yet support ActionScript 2 for

Remoting. Only ActionScript 1 . . . You can download either Joey Lotts' [AS2] port of AS1 Remoting or Justin Watkins'. I've used both and both work just fine."

Additionally, there is a nice tutorial on flash-db on using Justin's Remoting Connector for Flash MX 2004 (the examples there use amfphp but are equally applicable to Flash Remoting and OpenAMF.)

Although, reportedly, the community AS2/connector solutions work well, we haven't had the time to test them out completely and are not currently using either of them at Bits And Pixels. Instead, we've devised a simple solution that allows us to use the "official" AS2-compatible Netservices classes from Macromedia as we await the official AS2 release. Our solution was to load the includes using a dynamic class, which, in its briefest form, looks like this:
dynamic class com.ariaware.arp.remoting.Includes
{
    public static function getInstance ()
    {
        #include "NetServices.as"
        #include "NetDebug.as"
    }
}

For the inquisitive of mind, Ariaware is the name of a service that we are going to be launching very soon and ARP stands for Ariaware RIA Platform, our internal RIA framework. Not shown here, the Includes class is actually implemented as a Singleton.

In order to use our includes, we simply call them from the onLoad method of our main Application form as thus:
class com.ariaware.sampleApp.view.Application extends mx.screens.Form
{
    function Application ()
    {
        // We don't do anything in the constructor that involves child
        // components or screens (forms) since none of these have initialized
        // yet. Instead we carry out all such actions in the onLoad() event
        // handler.

        // Listen for the onLoad event
        addEventListener ("onLoad", this);

  // stop the timeline
  stop();
    }

    public function onLoad ()
    {
        // Do other stuff...

        // Load remoting
        com.ariaware.arp.remoting.Includes.getInstance();

        // More stuff...
    }
}

Ok, I lied, actually we load the AS1 Netservices classes by getting an instance of our GatewayConnection singleton, but I didn't want to complicate this example any further. This, in a nutshell, is a quick way to use the current official remoting classes with AS2 and forms.

It is puzzling why it is taking Macromedia so long to release the official AS2 version of Flash Remoting, given that the community has had enough time to release not one but two versions. Macromedia has announced the release, which leads me to believe that they will not be taking the alternative route, which would involve endorsing one of the current open solutions. I cannot help but think that not having an official and/or endorsed AS2/forms version of Flash Remoting is hurting the status of Flash Remoting as a supported Macromedia technology. That said, if the release is delayed further, we will probably end up going with Justin's solution in future projects and perhaps it will be up to the community itself to endorse and support this solution.