Just another Nodetraveller

Icon

Another blog about someone playing about with web development

RSS in Flash 2004

I haven’t had time to post anything recently but I have had time to quickly cobble together a little app using flash 2004 and its components. Yet another rss app but it shows nicely the usage of various components, old and new, that 2004 offers.

It uses the Accordion and TextArea UIComponents and the XMLConnector to load the urls of the feeds to download. Flash’s css support is also demostrated within the textarea. The actual loading of the feeds is done via remoting (2004 remoting and amfphp) which utilises a nice little rss parser from www.readinged.com called onyx-rss. The feeds are cached on the server and updated every 3 hours.

You can see it here. Depending on your connection it may take a few seconds to get the data so please be patient. If you want to download the fla,.as files and server code then grab this zip. Read the comments in the .as files if you want to run it on your server.

Update: Noticed that Jesse Warden also has a accordion based rss app. Besides the use of the accordion, it is different, but shows a slightly different way of doing the same thing. Go on take a look…

Design Patterns in Flash

Now Actionscript is OO, I thought it would be useful to try out implementing a design pattern in Flash. The pattern I chose is the Memento pattern, which is mainly used to implement “undo” functionality in applications. The reason I chose Memento is because its a pattern that uses interfaces and I wanted to explore this in AS 2.0. An interface is an object that defines methods but has no implementation.

Read the rest of this entry »

Flash TvGuide App

Okay, heres the flash client (only 47k!) for the TVguide webservice posted recently.

It’s quite a fairly simple movie using flash remoting and amfphp. I used amf to call my tvguide webservice via SOAP. Instead of having your swf call a specifc flash service, you call a special service which acts like a proxy to SOAP webservices. This service looks like this..

< ?php
// AMFPHP uses by default the PEAR::SOAP
// library, so you need to define in the
// gateway not to use that. In this case
// NuSOAP will be used

// change this based on your amfphp installation
include_once($_SERVER['DOCUMENT_ROOT'] . ‘/flashservices/app/Gateway.php’);
$gateway = new Gateway();
$gateway->usePearSOAP(false);
$gateway->service();
?>

You connect to this via NetServices..

this.netConn = NetServices.createGatewayConnection(”http://www.nodetraveller.com/flashservices/services/WSProxy.php”);

Then you specify the webservice you want by providing the endpoint to the getService method..

this.service = this.netConn.getService(”http://www.nodetraveller.com/webservices/tvGuide/tvGuideService.php?wsdl”,this);

and then call the webservice method you want…

this.service.getChannels(paramsObj);

The paramsObj is a value object holding any parameters the webservice method expects. When the data comes back you handle it the normal way..

Oh, and I had lots of fun playing about with the datagrid and creating a custom cell for it for the channel logo graphics.

Based on the Model View Architecture which works basically like this for those of you who don’t know yet:
The Model is an object that handles the remoting stuff and nothing else. It just connects to remote services and handles the data when it comes in. When the data does come in, it fires of an event to the View. The View is a listener of the Model so when the Model shouts, the View jumps. Now when the user interacts with the app, its the Controller that decides what to do; call a method on the Model or the View. Nice and easy…MVC ain’t completely perfect but its very useful…

You can see the actionscript files for the Model, View or Controller or download here

Webservices in Flash 2004

I’ve been playing about with the webservice connector in flash mx 2004. What I’ve discovered is that connecting to a webservice and using the data returned is really easy.

I’m using the tvGuide webservice (http://www.nodetraveller.com/webservices/tvGuide/tvGuideService.php?wsdl here at nodetraveller.com as one of the operations it provides is a list of channels which would look ideal in a listbox.

Here’s a quick guide to using a webservice:

Create a new document from a Query-Error-Response template. (This helps us with our simple example as it already sets up a webservice connector and a submit button in the form.

Click on the Webservice Connector (picture of a globe).

In the Properties panel, paste the url of the webservice WSDL in the WSDLURL parameter,and press return. Flash will now access the wsdl and find out what operations are available.

Click on the operations parameter and use the drop down to view the available operations. There should be two (getChannels and getChannelListings).

Select getChannels. For this simple example, theres no real need to use the other parameters though you can if you want. it won’t make any difference to our example.

Drag a Listbox and a TextInput component into the query Form. Name the Listbox channels_lb. Call the TextInput date. Enter todays date into the TextInput (make sure its in DD/MM/YYYY format). (strictly we should we using the response form as well but this is only an example)

Now select the webservice connector (you may have to select the application form first) and look in the component inspector (bottom right). Select the Binding tab. This is where you tell the webservice connector what to send to the webservice (and from what component) and what component to send the data to when received.

Press the + sign icon to add a binding. In the dialog that opens up, select the
date : String child of the params : Object.

Now we have to tell Flash what value to send. Select the bound to parameter and select the TextInput date in the dialog that appears. Finally change the direction parameter to “in“. What we’ve done is told Flash to get the value of the date TextInput (bound to parameter) and send it as a request to the webservice (direction parameter).

To populate the listbox with our returned data, create another binding and select
the results Array. Bind this to the listbox by configuring the bound to parameter. by selecting ListBox, and dataprovider : Array in the right hand column of the Bound To dialog . Make sure that the direction is set to “out”. We’ve just told Flash to pass the results Array received from the webservice to the dataprovider Array of the listbox. Doing so populates the Listbox.

And that’s it! And without writing any code. Test your movie and press the submit button…

You can download it here (you’ll need flash mx 2004 to view it)

This is a very simple example but I think for more complex ones, you would bind the WSConnector to a DataHolder and use the DataHolder events to notify UI components of the data change…

I feel the need for more experimentation….