Creating a user poll using Flash Media Server and Remote SharedObjects
NOTE: this example only works when Flash Media Server is running on my PC and it’s connected to the Internet.
Flash Media Server is good for a lot more than just streaming video and audio. With Remote Shared Objects you can store persistent data on the server to do things like create chat applications or a user poll.
I’ve created lots of polls in the past using AMFPHP – there’s one sitting to the far right column ->. It’s easy to do and very reusable. Storing data in a database has many advantages over using Remote Shared Objects but the RSO approach has one very distinct advantage: it automatically updates while you’re looking at the data. Check out the poll below. Submit your vote and then open this page in another Tab/Window ( I’d suggest opening in another Window so that you can see both at the same time. ) Submit you vote again and see it update the chart from your original vote. Cool, eh?
And the best thing of all is that it doesn’t take any extra code to achieve that. It pretty much comes with. It’s just a combination of the Sync event on the RSO and DataBinding.
| view source |
Getting Dirty
This example is very similar to my first two RSO examples except that I’m storing an ArrayCollection of Data Transfer Objects in the RSO. In practice it is no different than storing a String, Number, etc. except that FMS doesn’t actually notice that the value of the RSO has changed when you use setProperty().
All you have to do after calling setProperty() is call the setDirty() method on the RSO and that will do the trick for you. I have an entire post dedicated to setDirty with a simple example.
The best of both worlds
It would be very easy – if you have FMS and AMFPHP going for you – to set up a killer poll that used a database to store the data but used Remote SharedObjects to connect concurrent users so that when one user updated it would fire the Sync event for everyone viewing the poll and then we could go to the database to refresh the data. More about that later.







