Anyone who uses AMF, dpdk.nl’s ActionScript 3.0 remoting library is a fantastic robust, remoting service.

There are “rare” events that I didn’t consider after making several projects with it. These events, such as a connection issue, results in the user watching a spinning wheel for 10 minutes not realizing the app has jammed.

Inside nl.dpdk.services.remoting.RemotingEvent you’ll see four ‘enums’:

  • ERROR_NETSTATUS
  • ERROR_IO
  • ERROR_ASYNC
  • ERROR_SECURITY
  • ERROR_TIMEOUT

You’ll want to take care of each event, but ERROR_NETSTATUS and ERROR_TIMEOUT should be suffice. Here’s how you deal with ERROR_NETSTATUS:

var service:RemotingProxy = new RemotingProxy('http://localhost/', 'domain.MyService', ObjectEncoding.AMF3);
service.addEventListener(RemotingEvent.ERROR_NETSTATUS, onNetError);
public function onNetError(event: RemotingEvent) : void {
	errorCallBack('Connection Error! ' + event.getMessage());
}

This way you can deal with connection errors, etc. A user would likely close your site and never come back if it’s freezing all the time. Giving the user the option of resending the data would keep them there, and perhaps jiggle their cat 5′s.

Tags: ,

· · · ◊ ◊ ◊ · · ·

Getting Javascript to Talk to AMFPHP.

It’s a great advantage to have web applications degrade from HTML5 to Flash. Why? Because it allows a greater cross-compatability between browsers.

Transparent JSON in AMFPHP isn’t as easy as submitting POST data to json . php . You’ll quickly notice raising errors results in: Fatal error: Class ‘ErrorMessage’ not found in /amfphp 1.9/core/shared/exception/MessageException.php on line 63

To resolve this, put this in your service PHP file (in my case, MyService.php):

// JSON does not have Error Message
if (!class_exists('ErrorMessage')) { class ErrorMessage{};}
Another transparent issue is the lack of class serialisation. Simply set the _explicitType string in the Javascript class to the local VO object, and it will change them for you:
/**
     * loops through JSON array, replaces Arrays with serialized classes
     * @see mapClass($typeIdentifier) AMFBaseDeserializer.php
     * @param <type> $arr
     */
    public function mapJSONClasses (& $arr) {
        if(is_array($arr)) {
            foreach ($arr as $key => $value) {
                $this->mapJSONClasses($arr[$key]);
            }
            if(isset($arr['_explicitType'])) {
                $mappedClass = str_replace('.', '/', $arr['_explicitType']);
                $lastPlace = strrpos('/' . $mappedClass, '/');
                $classname = substr($mappedClass, $lastPlace);
                if(class_exists($classname)) {
                    $clazz = new $classname;
                    foreach ($arr as $key => $value) {
                        if ($key == '_explicitType') continue;
                        $clazz->$key = $value;
                    }
                    $arr = $clazz;
                }
            }
        }
    }

Tags: , ,

· · · ◊ ◊ ◊ · · ·