Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

Examining the Server-Side ActionScript

Examining the Server-Side ActionScript

There are two applications running on the Flash Media Server:

  • FileObj supports file access and filter functions pointing to your stream sandbox.
  • MyCollection supports FLVPlayback component functions.

Both run using the same default server-side ActionScript file, main.asc.

When you develop any Flash Media Server application, it is always easiest to start with the server-side ActionScript. Doing this allows you to debug and simulate the client-side actions using trace statements. This not only cuts down on your development time but prevents headaches later on.

You may notice that there are extra functions in main.asc in your FileObj folder. Notice there is more server-side ActionScript than is required for this application. This is what I use to handle all the file access commands in a familiar framework or API. I hope you will find this code useful and repurpose it for future file access functions.

Let’s go over a few key functions in this file.

Constructor for File Class

this.myFile = new File(name); 

This construct command creates an instance of the file class as object myFile. The variable, name, can be either a file or directory. In this demonstration, you will be passing your alias directory into here to gather information about it (by default, approot).

File.List for File Class

var dirList = this.myFile.list(filter); 

This is the list function from which the DataGrid on the client side takes information. The list method returns an array with an element for each file in the directory. You can filter this further with the filter function:

function filter(name)
{
if ( name.lastIndexOf( ".flv") != -1
|| name.lastIndexOf(".mp3") != -1){
return true;
}
return false;
}

For instance, if you wanted to build from this and display only JPEG images, you could use this filter and list command to control what is being transferred to your client.

Here is a brief summary of the other File Object functions:

  1. newClient.mkdir creates a directory defined by dirName
  2. newClient.remove removes the given file object
  3. newClient.rename renames the given function
  4. newClient.copy copies the object to a given variable
  5. newClient.closeFile closes access to the file object

FLV_Playback Server-Side ActionScript

One of the most common errors that occurs when streaming with the FLVPlayback component in Flash Professional 8 is when you forget to add the main.asc file into the streaming Flash Media Server video directory. I have included it as a part of this package so you will not encounter this problem yourself.

Comments