Omi: Dynamic Interactions Manager


Introducing the AS3 SWX Connecter

PLEASE USE NEW VERSION

I wanted to use SWX for an upcoming Flex project so I spent yesterday knocking up this AS3 SWX Connecter that currently works, mostly.

What is it?

Essentially its two files:

  • SWX.as - an AS3 compatible version of the SWX Object that mimics the core library one (source)
  • connecter.swf - an AS2 SWF that loads the data (source)

It is not a full port of SWX - it still uses AVM1 bytecode in the background, however it can be used with absolutely no code changes to SWX related code.

What’s new?

Callback functions are AS3 (say hello to Array.foreach()!) and so the scope doesn’t need to be specified:
result: resultHandler and result: [this, resultHandler] both work.

The core SWX library has been slightly modified to make it compatible with AS3 and to make it play nicer with the connecter. Changes to SWX.as, ExternalAsset.as and LoadManager.as.

See it in action

Here’s an AS3 version of Aral’s revolutionary number adding app:

AS2 Source | AS3 Source | Compare

How does it work?
LocalConnections are used to communicate between the connect SWF and the application, however the new SWX class abstracts away all of this, leaving just the original SWX functions. Thanks to Nolan Butcher for the starting point.

A Zip You Say?

Here: SWX AS3 Connecter ALPHA.zip (575kb)

Includes:

  • New SWX.as
  • connecter.swf and connecter.fla
  • Modified SWX library
  • Add Numbers - AS3 style

What’s wrong?

  • SWX.prepare() cannot be accessed - but who uses it anyway??
  • Setting debug: true breaks it - having looked through the SWX code, I still can’t figure out why
  • Does not work in Flex because the LocalConnection does not connect when the connecter is loaded via a Loader. Only way currently is to use a SWFLoader Component (creating a SWFLoader instance in AS does not work) but nobody wants SWFLoader MXML in their source code, defeats the point of abstracting everything to a library - maybe make a SWX component.

Anyone have any ideas on these?

TODO

  • Randomise LC ids
  • Allow user to specify location of connecter.swf

CakePHP: HABTM with hidden input tags

If you’re setting the IDs for a HABTM relationship in a hidden input tag to stop the user choosing the ID (I said user, not hacker - use proper AXOs to stop them!) you need to do set the name attribute to “data[Model][Model][]” NOT “data[Model][Model]”. So you can’t use the HTML Helper, you have to output the raw HTML (how last decade!)

Or just do $this->data[’Model’][’Model’] = array($id); before you save().

Applies to CakePHP 1.1, may not be relevant to 1.2.