Uploading Files To Amazon S3 With ColdFusion

Since version 9.0.1 (if I am not mistaken) ColdFusion supports Amazon's S3 file storage pretty much out of the box. The complexities of access control to your bucket is abstracted away and you can use S3 almost like a local file system. You can read more about it in the CF docs and on Ray Camden's blog.

My task at hand was to accept user submitted file uploads and store them in S3. According to the CF documentation the full set of cffile operations is supported, however I could not get it to work.
The following failed for me with a 'destination invalid' error:

view plain print about
1<cfset mydir = "s3://media.mysite.com/logos">
2<cffile action="upload" filefield="logo" destination="#mydir#" nameconflict="makeunique" charset="utf-8" />

Please note that in order for the s3:// syntax to resolve to your bucket you need to follow some setup steps which I won't cover here. Also watch out for a bug related to setting metadata.

[Read Full Article]

Shorthand For Sorting ArrayCollections In ActionScript & Flex

Here is a tip containing a quicker way to sort an ArrayCollection in ActionScript by using the underlying Array sortOn method. By quick I mean less code - I make no statement about performance.

Normally to sort an ArrayCollection you would need to create instances of both the Sort and SortField classes to arrive at something like this (untested code to give you an idea):

view plain print about
1var sort:Sort = new Sort();
2var sortField:SortField = new SortField();
3sortField.name = "myFieldName";
4sortField.numeric = true;
5sortField.descending = true;
6
7myCollection.sort = sort;
8myCollection.refresh();

However since the source property of the ArrayCollection class points to the Array that acts as the source of the Arraycollection's data you can mess with it if you like (it's a bit naughty as you are not meant to do this and your mileage may vary).

So therefore to sort the above example 'myCollection' numerically by 'myFieldName' you could to this:

view plain print about
1myCollection.source.sortOn('myFieldName', Array.DESCENDING | Array.NUMERIC );
2myCollection.refresh();

I'm sure someone will tell me off for this but here you go. This worked for me for my purposes and it seems a lot simpler. And I like simple things.

Converting And Editing AVCHD (.mts) Files On OSX

A quick note about this article: I chose a slightly misleading title in order to help people find it more easily as most would not know that a search for 'rewrapping .mts files' is what they may be after.

This post is about rewrapping .mts files to make them compatible with QuickTime; it is not about re-encoding or editing .mts files (but rewrapping will make them editable using most common video editing tools).

Many common camcorders and digital cameras - in particular Panasonic and Sony models - produce video files in AVCHD format, with file extension .mts, .m2ts or .m2t. These files often do not play back natively unless you install a third party video player such as VLC.

I was getting a bit annoyed at the fact that quick preview in Finder would not work with .mts files and that the format is generally a bit of a nuisance (iMovie for example won't find any compatible files if you tell it to look in a folder that only contains .mts files). Moreover I was looking to stitch some clips together which in turn was made more difficult by the .mts format.

[Read Full Article]

Enable Ping ICMP Replies For Amazon EC2 Windows Instances

Here's a quick tip on how to configure a Windows Amazon instance to successfully respond to ping requests.

By default an EC2 security group does not allow ICMP ping requests, and in some cases the internal Windows firewall will also block it. You therefore should check both settings if you want to be able to ping your EC2 Windows instance.

Step 1: Check Windows Firewall Settings
To enable the Windows firewall to allow ping request check that under 'Inbound Rules' the setting 'File and Printer Sharing (Echo Request - ICMPv4-In)' is enabled. The icon should turn green if the rule is enabled.
Alternatively you can use the commandline option:

view plain print about
1netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=allow

This should take care of the Windows firewall.

[Read Full Article]

Adding event sounds to the Chat Component (by Gani)

In this tutorial we will be explaining how to add a sound in the chat component so that when a message is received or sent it will be played.

First of all, open up your application and in the first frame create the code for the sound object that will be played.

You are going to need a sound to play, so go ahead and bring a sound into your library that you would like to be played when you send and/or receive a message . Once you have the sound file imported, right click on it in the library and choose linkage. Enter a name for your sound and press ok.


In this example the name of our sound is 'chimes'

Now we need to create the sound object.

chatSound = new Sound();
chatSound.attachSound("chimes");

The next thing we need to do is make the function that will play the sound.

function playSound(){
   chatSound.start();
}


Click an instance of the chat component onto the stage, rightClick on it, select 'edit in place' and find the layer called actions. Select the first frame to reveal its code in the actionscript editor.

You have to find the following two functions
FCChatClass.prototype.receiveMessage = function( mesg ) and
FCChatClass.prototype.sendMessage = function(mesg)

You need to add the following line of code to the sendMessage function:
   _root.playSound();

You should also place the following piece of code inside the receiveMessage function. This will check to make sure that the sound does not play when the message is coming from yourself but only when it comes for another user.
if(mesg.slice(25,this.username.length+25)!=this.username){
   _root.playSound();
}


The completed code should look like this:
FCChatClass.prototype.receiveMessage = function( mesg ) {
   this.history_txt.htmlText += mesg;
   this.history_txt.scroll = this.history_txt.maxscroll;
   if(mesg.slice(25,this.username.length+25)!=this.username){
      _root.playSound();
   }
}

FCChatClass.prototype.sendMessage = function(mesg) {
   this.nc.call( "FCChat." + this.name + ".sendMessage", null,    this.message_txt.text );
   this.message_txt.text = "";
   _root.playSound();
};

You're done. (and keep the sounds subtle or we won't visit your app ;-)

Running Flashcom Server alongside IIS

If you are running your own webserver and maybe have bought a Flashcom license alongside it then you might be tempted to run both your webserver and flashcom apps on the same box. And why not, after all we don't all have multiple machines at our disposal.

The following configuration is one that I have set up several times. I am running IIS (Microsoft's Internet Information Server) and FCS (Flash Communication Server 1.5.2) on the same server which uses Windows 2000 Server as its OS.
It's possible to use other webservers like Apache for this but in this tutorial I will focus on IIS and FCS on Windows so keep that in mind if your setup is different.

The principles behind it are the same on any server: we want FCS to use other ports than the standard 1935 because we want to use http tunneling. As you might know tunneling uses port 80 (usually used for 'normal' http website traffic) or port 443 which is common for SSL traffic. Both ports are often open on firewalls hence the tunneling there ;-)

The problem is that no two services on one IP address (read: our machine) can use the same port - we would end up having FCS and IIS competing for port 80, and one service would win. Should FCS start up before IIS then it might grab port 80 and not allow any website (IIS) traffic through it, effectively making any website unavailable. that's when you would get the alert in IIS saying 'address is already in use'. Let that be your warning sign.

The whole problem is easily solved in a few steps.

Step 1 - Assign a second IP address to your server
If your server is hosted remotely simply ask your hosting provider for a second IP. Sometimes they charge for this but it's usually a $10 one off fee, that's all. Your host might ask you why you want the secondary IP, tell them you want to run 2 services on port 80.
If you are running your own server then assign a secondary IP yourself, how this is done is beyond the scope of this article. You'll find this information on the net.

Step 2 - Stop IIS grabbing all available IPs
By default IIs will bind to all IP addresses it can find. To prevent this from happening you need to disable socket pooling in IIS. This is quite easily done and you can see a full description in this article.

Addition: since this tutorial was released I have also installed FCS on Windows 2003 Server and the process of stopping IIS grabbing all IPs is different to Windows 2000. You need to use a utility called httpcfg.exe, read about it here.
The following steps apply to Windows 2000 as well as Windows 2003.

Step 3 - Bind IIS to one IP address
For example say your host has assigned the following two IP addresses to your server: 123.123.123.1 and 123.123.123.2. We decide we want to bind 123.123.123.1 to IIS.
To do this open Internet Information Services Manager (start > control panel > Administrative Tools > Internet Information Services). Right-click on the first website listed and select 'Properties'. The following panel (or similar) should pop up:


In the dropdown next to 'IP Address' you can now select one of all IP addresses available on this machine. You should select the one of the two you have available. Also add any host headers if necessary and repeat this process for every site on your server, always making sure that no site has (All Unassigned) selected. Each site should bind to the same IP address, we will later bind FCS to the other.
For information on host headers consult the Microsoft website. You should know how these work if you run your own webserver.

Step 4 - Bind FCS to the other IP address
We are almost done. IP addresses in FCS are configured via a file called Adaptor.xml. You can bind FCS to any IP or all IPs available. By default FCS tries to bind to all IPs available so we need to edit the Adaptor.xml file to change this. Adaptor.xml is inside the conf\_defaultRoot_directory. Open it for edit.
Find the <HostPort>:1935</HostPort> tag. In this case FCS binds to port 1935 on any IP address. In our example we want it to bind to 123.123.123.2 on port 1935, 80 and 443.

Therefore our host tag should look like this:
<HostPort>123.123.123.2:1935,80,443</HostPort>

Save the file, restart FCS, restart IIS and you are done. You can now run websites and FCS on the same machine with http tunneling fully functional.

I *think* that the admin port 1111 for FCS will still bind to both IPs but this won't affect IIS in any way. Also I you do not want to use tunneling then IIS and FCS live happily alongside on a single IP.

Configuring Flashcom Server with multiple vhosts

Time for a new tutorial and this time I will try and explain how you set up and configure your Flashcom Server with multiple vhosts. It should be noted that only the Professional Edition supports vhosts so if you run the Developer or Personal Edition then you will not be able to add additional vhosts. Dev and Personal Edition will only run apps under the _defaultVhost_

The following steps apply to the Windows version of Flashcom Server but apart from Windows style filepaths you can take a lot away from this tutorial for Linux installations, too.

Flashcom Server uses XML files for configuration and these work in several levels starting at the server level (Server.xml) down to adapter (Adapter.xml) and vhost level (Vhost.xml) The last level is Application.xml which as the name says is responsible for configurations on an Application level.
The XML files are well commented and essentially pretty easy to maintain. To set up a working vhost you will normally need to edit 3 files:
- Server.xml, Vhost.xml and Application.xml

Server.xml can be found in the root of the /conf directory; Adapter.xml can be found inside the _defaultRoot_ directory and both Application.xml and Vhost.xml can be found under _defaultVHost_

This is how your file structure would look like after a standard Flashcom installation in Windows (only _defaultVHost_ is available)


Server.xml
Strictly speaking you do not have to edit server.xml to add a vhost. This is because the vhost entry in server.xml is only needed so that you can later add vhost administrators via the admin console. Adding a vhost to server.xml does NOT actually add the vhost to the server config. This might be a bit confusing but it's actually the process of creating the necessary folders under your adapter level which creates the vhost.

Having said that I would always recommend you add your vhost to server.xml to keep things organised. This will also allow you later to modify the vhost admins via the admin console. So here's how you add the entry to Server.xml. you need to copy the entire <VirtualHost....>...</Virtualhost> entry, basically the whole chunk that you see in the pic below.

Next you need to give your new vhost a name. This is important and you should always name it after the domain (or subdomain) the you use to later access it. Say for example your main domain is myflashcomhost.com then why not call this vhost vhost1.myflashcomhost.com. It is important to understand that this new subdomain must resolve to your Flashcomserver IP address. If it doesn't then you'll never be able to connect!

So for this example I will call my vhost vhost1.myflashcomhost.com and this is how the entry in server.xml should look like:

Adding the vhost folder
This next step is important as it will actually create your vhost. You have to create a new folder under your adapter level (in our example under ...\conf\_defaultRoot_), on the same level as _defaultVHost_. I sometimes just copy the entire _defaultVHost_ and then rename it. Warning: The name of this folder needs to correspond to your domain that you will use to access this vhost, in our example vhost1.myflashcomhost.com.

Your folder structure under /conf/_defaultRoot_ should now look like this:

This has in effect created the new vhost on your server.

But in order to be able to actually use the vhost you need to configure the <ScriptLibPath> in Application.xml and also the <AppsDir> in Vhost.xml. If you have created your new folder by copying _defaultVHost_ then those 2 files already exist inside your new vhost folder. If they don't then you need to copy them over from an existing vhost. You should also create a folder called 'admin' inside vhost1.myflashcomhost.com if you want this vhost to be able to accept admin connections. Have a look inside _defaultVHost_ for an example.

Adding the corresponding applications folder for your vhost
The Flashcom Server configuration is usually split up in 2 parts: the admin files under /conf to which only the server admin has access to and the vhost folders themselves (yet to be created) which will host your actual serverside scripts such as main.asc. The vhost folders can be made available via FTP for example to allow access for vhost admins. It is also a good idea to add a dedicated scriptlib to each running vhost.

In a nutshell what you have to do is create another folder to which you map your appsdir and scriptlib. This folder should not reside under /conf and it should not be accessible from the web, only via FTP. This applications folder is not the place from which you serve your swf files!
If you are planning on running a webserver on the same machine as your Flashcom Server then I recommend you read my tutorial on IIS and Flashcom, it gives some tips in regards to IP addresses and ports.

In my example the applications folder lives under C:\Inetpub\flashcom\applications (note that it is not under wwwroot and therefore not accessible from the web) but you can basically map it to wherever you see fit.
I call my new folder 'vhost1' and create 2 more folders inside it called 'apps' and 'scriptlib'. I then copy my scriptlib files from abother vhost into the scriptlib folder. My folder structure now looks like this:

Now we need to map appsdir to C:\Inetpub\flashcom\applications\vhost1\apps and map scriptlibdir to C:\Inetpub\flashcom\applications\vhost1\scriptlib

The correct XML entry therefore look like this for Application.xml

and like this for Vhost.xml


And that is pretty much all there is to it. It sounds a lot more complicated than it really is and I recommend you just try it out. I always restart my server just for good measure although I have been told that this is not strictly necessary.

a coomon problem oftne is that the new vhost domain (in our example vhost1.myflashcomhost.com) doesn't actually resolve correctly to the FCS IP and in that case you will never successfully connect. I therefore always open my admin console and check if my connection attempt actually hits the server - and I keep a particular close eye on the fact that the connection attempt does not connect to _defaultVHost_. If it does connect to _defaultVHost_ instead of your new vhost then you might have a config problem.

If your connection does not hit the server at all then the problem is likely DNS related.

If your connection does hit the Flashcom box but fails in some other way then nine times out of ten the admin console will give you some clues as to what is going wrong.

If you are still stuck after that then I recommend reading the Flashcom Server docs at http://www.macromedia.com/support/flashcom/documentation.html and in particular the first 2 PDF's called Installing Flash Communication Server and Managing Flash Communication Server.

There are also some interesting Live Docs available at http://www.macromedia.com/livedocs/flashcom/mx2004/index.html

Displaying FLV video previews in a listbox

Download Source

This video tutorial will explain how you can create an XML-driven listbox component which displays thumbnail previews of a series of flv files. The download of each flv file is stopped as soon as the preview is displayed, allowing for a large amount of flv files to be previewed, scrolled through and played.

Requirements: You need Player 8 and tolerance for a heavy german accent :-P


Credits
Lisa Larson for the original article
Srinivas Manapragada of Macromedia for the cellrenderer
Craig Goodman of Macromedia
Akamai for hosting the video

Clearing the Chat History (Part 2)

As promised here is the second part of our tutorial. We will now take a closer look at how we can clear the chat history by clearing the server-side shared object that holds it and broadcasting this change to all connected users.

This tutorial presumes that you are using the pre-build communication components from Macromedia.

A fortunate fact is that all functionality to do what we are trying to achieve is already built into the components, all we need to take care of is how to call upon these functions.

Step one: Make sure clients are allowed to clear the history.
Take a look at the chat.asc file, it includes all the server-side code that works alongside your chat component (and after all that's where the chat history is displayed).

Line 35 of chat.asc should look like this
FCChat.prototype.allowClear = true; // Allow clients to clear history

If allowClear is set to false then make sure you change it to true.

Step two: Making sure you know what you are doing ;-)
The function that you will be calling in a minute is located from line 90 of chat.asc, it starts like this:
FCChat.prototype.clearHistory = function( client ) {
...
}

If you (somehow, anyhow) call this function it will first check if allowClear is set to true (which it is now), then it will clear the chat history by running these four lines of code
this.history_so.setProperty( "history", null );
this.history_so.flush();
delete this.history;
this.history = new Array;

and finally it will broadcast this change to all connected clients.
// Broadcast a clearHistory command to all clients
this.message_so.send( "clearHistory" );
return true;


So far that's very easy, you don't even have to write any code at all.

Step three: call the clearHistory() method
Easier said than done... but then again it's not that hard. I will show you one way of doing this very easily and it will allow you to clear the chat history by typing a 'secret' string into the input field of your application's chat window.

Line 73 of chat.asc contains the method sendMessage() and here it takes two parameters, one of which is mesg - the message string that has just been received and will now be sent to all clients. However before it gets sent we will intercept mesg, parse it and if the string matches our secret command then we will call the clearHistory() method.

This is easily done by simply adding the following piece of code on line 74 (and inside the sendMesage() method:
if (mesg.toLowerCase() == "secretstring"){
   this.clearHistory();
   }
else {
...
}


Basically all the original code will now be inside the else statement and will only be executed if the string does not match our secret command. However if you were to type "secretstring" (or whatever you have hard coded on line 74) then only this.clearHistory(); would run, resulting in the deletion of the chat history and a broadcast of this change to all connected users.

Moreover, none of the connected clients will ever see the secret string because it will not be broadcasted.

Remember that you must restart your application from the application inspector, this will reload the modified chat.asc file.

Hopefully this little tutorial will get you started. There are loads of other ways of calling clearHistory(), for example you could call it every time a user connects (but then again that's a bit silly) or every time the last user disconnects (makes more sense).

I leave that part up to you but the most obvious option is probably writing your own server-side function which you can call by pressing a pushbutton inside your client movie - for example you could have some kind of admin movie that is different to all the 'public' ones. For more information take a closer look at the call() method of the client-side communication actionscript dictionary.

Good luck and keep those suggestions coming in.

Check the first part of this tutorial
.

Clearing the Chat History (Part 1)

This is one of those subjects that keep coming up again and again: How to clear the chat history.

Most commonly known chat systems do not show you the conversations that have gone on before the user logs in. Developers therefore often like to emulate this behaviour in their FlashCom applications.

There are several ways of clearing a chat. The chat history is held in a server side persistent shared object (SSPSO) by default. If you clear the contents of this object then all clients will reflect this change immediately through their onSync event.

The following tutorial presumes that you are using Macromedia's Communication Components.


Option 1: Clearing the history on the client side only - the lazy way
Lazy way meaning you are not actually clearing the shared object which holds the history on the server but you are simply resetting the chat text field inside one client's movie to an empty string, effectively clearing it.

All you need to do is for example to add the following code to frame one of your movie (in this case your chat component instance must be called chat_mc):
chat_mc.history_txt = "";

To make it more robust you can also put this line of code into an onLoad() event of the chat_mc movie or provide a function that can be called by the user, for example when clicking a button.
Your function on frame 1 of the main timeline could be:
function clearHistory() {
    this.chat_mc.clearHistory();
};


and all you then need is a pushbutton, it will call the function clearHistory() when clicked by a user:


Hopefully this will point you in the right direction for integrating it with your own application. Next week we will look at how to clear the server side shared object on the server and broadcasting this change to all connected users, clearing the chat on each client.

Make sure to also check the second part of this tutorial
.

More Entries