Monthly Archive for August, 2007

How do you pronounce SWX?

It's pronounced "swix".

The Public SWX Gateway

There is a public gateway that you can use on swxformat.org to call the various SWX APIs without hosting your own PHP installation of SWX.

Take a look at the Start Page for the SWX public gateway. This is the same Start Page that you will see when you install SWX PHP or the SWX PHP MAMP Bundle (only it's called start.php instead of index.php here on swxformat.org).

The URL for the public gateway is:

http://swxformat.org/php/swx.php/

You are encouraged to make use of the SWX public gateway but please do not flood it with so many requests that it resembles a denial of service attack!

The public gateway also hosts versions of the SWX Service Explorer and SWX Data Analyzer.

SWX Credits and Acknowledgments

Conceived, developed, and maintained by Aral Balkan.

Hosted on OSFlash; the home of the Open Source Flash community.

  • Folkert Hielema: For creating Swadge and Swoot, and for your support, invaluable help and collaboration. It's cool to feel that I'm not working on SWX alone! :)
  • Larry Mahony: Thanks to your bug report, SWX runs well on PHP 4.4.3 too now! :)
  • Wouter Verweirder: For contributing the non-cURL fallback routine for the SWX Twitter API. Thanks to your code, developers without cURL can use the SWX Twitter API too!
  • Steve Webster: Refactoring the service class, TheTenWordReview API.

To everyone whom I’ve learned from, thank you!

Igor Kogan and Wang Zhen for Flasm and Matthias Kramm for Swfdump (part of Swftools). My life would have been astronomically more difficult without these two excellent SWF disassemblers.

Douglas Crockford for thinking different and giving us JSON.

Tony Million for making 0xED, a hex editor for OS X that was extremely useful for viewing SWF bytecode.

Patrick Mineault for creating AMFPHP. I hope SWX and AMFPHP become bosom buddies!

Apple, for making my amazing MacBook Pro and for giving me OS X. After 22 years of increasing amounts of frustration with DOS and Windows, I love using a computer again. My Mac has definitely made me a better developer!

Twitter for keeping my connected and the cafe at my local Borders, where a portion of SWX was written, for giving me a change of scene in the mornings.

The lovely folks at MAMP for making it child’s play to get a development server up and running on OS X and the gang at ApacheFriends for doing the same for Windows and Linux users. SWX will include custom distributions of both of these packages that also contain SWX.

Macromates for making Textmate. It’s my best friend :)

SimpleTest, AsUnit, and SVN for giving me piece of mind.

My friends at Adobe for making Flash, Flex and Apollo possible.

Our wonderful OSFlash community sharing your knowledge openly and for giving me inspiration and hope every day. You guys rock!

Brighton, my fellow Brightonians, and our lovely little geek community here in the UK for your inspiration and friendship.

A special thank-you to Niqui, Pete, Dave, Paul, Justin, Danny, Jeremy, John and Serge, for your feedback, support and encouragement.

And last, but definitely not least, a big thank-you to my parents for your lifelong support and for always encouraging me regardless of what I’m doing. There’s a bit of you in everything I do.

SWX Licensing & Legalese

SWX, swxformat.org, Datum (the SWX logo) are trademarks of Aral Balkan.

SWX, the SWX web site and any other related products are offered as-is without any warranties or guarantees of any kind as per the Terms and Conditions.

SWX is not affiliated with Adobe. Adobe and Flash are registered trademarks of Adobe, Inc. All other trademarks and copyrights belong to their respective owners.

SWX has several different components, each of which is licensed separately. Specifically, there is the (A) the SWX Server, (B) sample code, examples (both server-side and client-side) and the ActionScript API, and (C) documentation.

The spirit of licensing these components separately is to make sure that the correct license is chosen for each component to allow users as much freedom as possible in making use of SWX.

A. SWX Server

License: Creative Commons GNU GPL.

The SWX Server includes the SWX gateway, SWF assembler and all other server-side components that are integral to the functioning of SWX.

The rationale here is that if you change or improve the SWX Server and distribute the results, you should make your source and improvements available under the same license so that everyone benefits.

The GNU GPL license is basically the same license that Amfphp uses so you can use the SWX Server anywhere you are able to use Amfphp.

B. Sample code, examples, and the ActionScript API

License: MIT.

Sample code and examples (on both the client-side and server-side) and the SWX ActionScript API are released under the more liberal MIT license. This applies to all samples and examples that come with the various SWX download packages and to those on aralbalkan.com and swxformat.org.

This means that you can modify and use the code for the samples and examples (PHP, Flash, ActionScript, etc.) in your personal or commercial projects regardless of whether they are open-source or close-source. This includes the ActionScript API for SWX (the PHON serializer, etc.) So, to make it crystal clear, if you make a Flash or Flex application that is based on the Flash and ActionScript code in SWX, you can pretty much do whatever you like with it (except remove the copyright notice in the code or hold me liable for damages, etc.)

C. SWX documentation and blog post content

License: Creative Commons Attribution-Share-Alike 2.0 UK: England & Wales Licence.

Basically, you are free to do what you like with the SWX Documentation and blog post content as long as you give proper credit and share your modifications under the same license.

Accessing the result property

Using the SWX Data Analyzer to confirm that your SWX data is loading correctly into Flash is great, but what you really want to do is display that data in Flash. You're going to implement a quick hack to get it working and we can evolve the application later to improve it.

Add a TextField instance to the Stage and give it the instance name status.

Next, create an onEnterFrame handler that prints out the value of the result property of the dataHolder movie clip into the status text field.

The complete script at this point is shown below:

dataHolder.serviceClass = "Calculator";
dataHolder.method = "addNumbers";
dataHolder.args = "[35, 7]";
dataHolder.debug = true;
 
dataHolder.loadMovie("http://localhost:8888/php/swx.php", "GET");
 
function onEnterFrame()
{
    status.text = dataHolder.result;
}

Test the movie and you should see the number 42 appear in the status text field.

Now stop for a moment and take a deep breath: You now know exactly how SWX RPC works!

You didn't import any classes, you aren't using an API, you didn't include any external code whatsoever. SWX is completely native to the Flash platform and, if you want to, you can make use of it by using only built-in Flash features like you did here.

Compare this to other technologies like Flash Remoting. Do you actually know exactly how Flash Remoting works? There are numerous classes, lots of code, etc. There's some magic involved that you don't really understand. Not so with SWX RPC. With SWX RPC, your data arrives in native Flash format.

It's important for a technology to be so simple that you can actually conceptualize it completely. However, that doesn't mean that the above method is the way you'd want to use SWX PHP on a daily basis.

For one thing, take a look at how you set the arguments. You placed them in a string. In fact, what you did was serialize the arguments you're sending in JSON format. It's not confusing or difficult to this by hand if you are sending simple arguments like two numbers but what if you wanted to send an array of complex objects to the server? It would get tiresome and impractical very quickly.

The example you just created uses the No API method. In other words, you used pure Flash. No additional classes.

However, to make your life easier, you may want to use just a little API. Specifically, a method to serialize your arguments into JSON format for you would be nice. The SWX ActionScript Library, which comes with SWX PHP, provides just such a method for you (and much, much more!)

SWX Data Analyzer

Before testing the movie, open the SWX Data Analyzer in a separate browser window.

Swx Data Analyzer

SWX Data Analyzer is a debugging tool that shows you the SWX data that arrives inside your Flash movie.

To make SWX data that loads into the Flash player appear in Analyzer, you turn debug mode on. That's what the line dataHolder.debug = true does.

Now, test your movie and then look in the Analyzer. If all went well, you should see the number 42.

Calling SWX PHP methods from Flash

You've verified that your server-side service method is working correctly by using the SWX Service Explorer. Now let’s call this method from Flash.

  1. Open up Flash and create a new FLA (ActionScript 2). You can set the publish setting to Flash 7 or 8.
  2. On Frame 1 of the new FLA, create a movie clip instance and give it the instance name dataHolder.
  3. Create a new layer and call it Actions. On the Actions layer, add the following code:
dataHolder.serviceClass = "Calculator";
dataHolder.method = "addNumbers";
dataHolder.args = "[35, 7]";
dataHolder.debug = true;
 
dataHolder.loadMovie("http://localhost:8888/php/swx.php", "GET");

That's it! That's all the code you need to call the addNumbers method on the Calculator service class in PHP and pass it the numbers 35 and 7 as arguments. The loadMovie calls the SWX gateway and passes to it any of the properties you set on your movie clip. In this case, since we are sending a small number of arguments, we use the GET HTTP encoding method. We could just as easily have used POST.

Testing the Calculator service with the SWX Service Explorer

Return to the SWX Service Explorer (or open it if you didn't earlier) and you will see the Calculator class you just created. Click on it and you will see the addNumbers() method. Enter two numbers in the $n1 and $n2 fields and press the call button to test out the method. You should see the sum returned in the results area.

How simple is SWX? Moo card example.

Swx Flickr Tutorial Moo Card

SWX is so simple that instructions for getting data into Flash using it easily fit on to a Moo card (ask me for one if you see me around!)

To get a list of the most recent 100 photos from Flickr into Flash, do the following:

  • Open up the SWX Data Analyzer
  • In Flash, create a new FLA and create a movie clip on the Stage. Give it the instance name loader.
  • Write the following code on to the frame that the loader movie clip is on:
loader.serviceClass = "Flickr";
loader.method = "swxPhotosGetRecent";
loader.debug = true;
 
loader.loadMovie("http://swxformat.org/php/swx.php", "GET");

That’s it! Test your movie and look in the SWX Data Analyzer to see the results being loaded in to Flash from Flickr. That’s how simple SWX is.

If you want to display the results from within Flash, create a long, single-line dynamic text field on stage and give it the instance name status. Add the following code to the timeline:

function onEnterFrame()
{
    status.text = loader.result.photo[0].src;
}

Initially, the status text field will display undefined until the data is loaded and then it will display the URL of the first photo from the list of recent photos that is loaded from Flickr. Notice how you can access the results as native Flash objects the moment they’re loaded. No deserialization or massaging of the data is necessary!

In this example, you used the SWX Public Gateway (http://swxformat.org/php/swx.php) which you're welcome to use in your own applications to create mashups with the supported APIs (Flickr, Twitter, etc.) without having to host or write any back-end code yourself.

Systemwide simplicity

A system is only as simple as its most complicated part. It's not enough to just simplify individual components and processes, you must also simplify the relationships and interactions between components and sub-processes. Systemwide Simplicity takes a wider approach to simplicity that involves understanding and supporting the entire user experience.

It is thus my aim to make it as easy as humanly possible for Flash developers to start creating data-driven Flash applications from the moment they arrive on the SWX homepage to the moment they first get data into Flash using SWX RPC.




Bad Behavior has blocked 10416 access attempts in the last 7 days.