I am building HTML5 applications at Sencha. It is a great platform, take a look...

 

  Ted Patrick - Developer Relations @ Sencha


   Note: This is the personal blog of Ted Patrick. The opinions and statements voiced here are my own.



FDOT - Making hard things easier.

DIGG IT!     Published Wednesday, August 19, 2009 at 3:34 PM .

Today I posted build 32 for public download of Project FDOT( f.* ). FDOT is a collection of ActionScript 3 classes that make hard things easier.

DOWNLOAD FDOT_BUILD_32

The first release includes 3 classes:

f.net.Load - Load text to binary with one method call and one callback.
f.net.Message - Simple callback messaging for classes.
f.data.ObjectStore - Simple object database for storing anything.
(Includes an awesome JSON lib by Darron Schall via as3corelib )

The first thing that you will notice in FDOT is a sharp departure from OOP and addEventListener in preference for simpler method calls and the use of callbacks. I have long felt that addEventListener is overkill and with the addition of method closures, callbacks are a very underrated technique. Loading external data in Flash Player used to be drop dead easy, like no think easy. Today it isn't, it typically requires you to subscribe to 5 events create 5 methods all typed to catch different events and even then knowing what to do when things happen leaves many frustated. Why was this so easy before? Why do we need to do all this work just to load data or swf files?

The thing is that having great low level networking classes is great but we need to build simpler code upon these. That is the intent behind f.net.Load. Simplify the loading of all types of data into Flash Player. Make it clean, orthogonal, and easy to use. Here are some samples:

//note that all Load methods have the exact interface!
Load.text( url:String , callback:Function , params:Object=null );

//text
//load text via post using this.load method as callback
Load.text( 'test.txt' , load , { method:'post', data:{ a:1 } } );

//json
Load.json( 'test.json' , load , { method:'post', data:{ a:1 } } );

//xml
Load.xml( 'test.xml' , load , { method:'post', data:{ a:1 } } );

see a trend yet?

//querystring
Load.querystring( 'test.qs' , load , { method:'post', data:{ a:1 } } );

//stream
Load.stream( 'test.png' , load , { method:'post', data:{ a:1 } } );

//image
Load.image( 'test.png' , load , { method:'post', data:{ a:1 } } );

//swf
Load.swf( 'test.swf' , load , { method:'post', data:{ a:1 } } );

//binary
Load.binary( 'test.png' , load , { method:'post', data:{ a:1 } } );

The best part is that you need only one method to handle all callbacks. Here is how it works. Simply define a method with a single Object as its parameter, your done. Based on the 'type' property within the object passed in the callback you get different data. Some callbacks are for Load.PROGRESS, Load.OPEN, Load.HTTPSTATUS and you can use these constants to filter like so:

public function load( event:Object ):void
{
    if( event.type == Load.COMPLETE ){
        trace( ' < loadMovie COMPLETE: ' + event.data );
    }else if( event.type == Load.PROGRESS ){
        trace( ' < loadMovie PROGRESS: ' + event.percent );
    }
}


When Load.COMPLETE is passed, you get event.data, and when Load.PROGRESS, you get event.percent, event.bytesLoaded, etc within the passed object. I have been thinking about making a single callback Event type to make this easier still but that is for a future version.

In the build there are samples of every feature of the FDOT library. I am working to add in ASDOC comments and get the initial documentation generated too along with some late breaking additions of Load.amf, Load.csv, and Load.yaml, pending massive disruptions. Also planning to expand the features within the parameters argument to support PRAGMA headers, Caching support via ObjectStore, and a server side proxy to allow for full REST support ( I might need some CF/PHP/JAVA help there).

I would ask that if you find any bugs, email me at ted@adobe.com. Plans are underfoot to move this under GITHUB later today but some networking is holding me back, ugggh.

The goal here is to make hard stuff simpler so you can spend your time making awesome complex stuff. Loading has been a huge barrier for Flash Player since ActionScript 3 arrived and I would hope this helps a bit. Long story short simplicity and ease of use are driving all API decisions on FDOT, and if you see a simpler path, I am all ears.

DOWNLOAD FDOT_BUILD_32

It has been a blast working on FDOT and it is great to set it free as open source under a BSD License. Use it as you wish and send me feedback on what to do next.

Cheers,

Ted :)


Where to find me:

Ted on Twitter - @__ted__
Ted on Adobe Groups
Ted on LinkedIn
Ted on Facebook
Ted at Adobe

Latest

Lists

Links

Jobs

city, state, zip

Archives