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
Hello,
This is great work and just what I need, unfortunately your example is throwing the following errors:
SWX.as:34: 1120: Access of undefined property onConnStatus.
SWX.as:35: 1120: Access of undefined property onReceivedError.
Any ideas?
José
Posted August 27, 2008, 1:26 pmAh, I just realised this is a Flex app, wereas I was attempting to use it within the CS3 IDE. This may well be the casue of my errors.
Posted August 27, 2008, 3:21 pmThe SWX.prepare() is there to use when you don’t use the SWX API scripts but only loadMovie your data.
For flex (i’m so much a starter at flex afters years of Flash) you could maybe create a swc file from Flash IDE to use in Flex, else maybe it will not load during Security. Either way mail me and i’ll try and help you get this thing completed and ‘production’ ready.
Thanks for your efforts on SWX
Posted September 10, 2008, 12:15 amJose:
Please use the new version that bug has been fixed.
Folkert: I’ll gladly accept help on this. I reckon a custom component is the most Flex-y thing to do, since a SWC would not allow binding etc.
Posted October 8, 2008, 12:51 amThis connector is great and does what it says, but does it not defeat the whole purpose of the SWX data format, that being not having to serialize the data upon arrival. I am wishing to send a whole bunch of data to Flash player and it was so slow with XML and still slow with AMF, then I found SWX and it was nearly instantaneous. I would like to port my app to AS3 but now SWX for AS3 is not existent and this seems like it will not be any faster than AMF because of the serialization step.
Does it seem likely that SWX for AS3 will truly exist anytime in the foreseeable future? I have not delved into the specifications so do not know what the challenges for the bytecode assemblers are, but I imagine they must be great or this would be done already. Seems like it has died instead? Would love to hear somebody please correct me!
I will try this in the meantime and see if it slows everything down too bad.
Posted November 13, 2008, 4:26 pm