| By Robert Sandie | Article Rating: |
|
| February 26, 2006 05:00 PM EST | Reads: |
18,991 |
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 other functions in this main.asc file in case you want to repurpose them for other applications using File Object. To find more specifics on the details of these function, read the Flash Media Server LiveDocs, which are a great resource for more information on each of these functions.
Here is a brief summary of the other File Object functions:
- newClient.mkdir creates a directory defined by dirName
- newClient.remove removes the given file object
- newClient.rename renames the given function
- newClient.copy copies the object to a given variable
- newClient.closeFile closes access to the file object
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.
Examining the Client-Side Setup
This client-side setup is rather simple because it is built with pre-existing components using basic OOP principles (Figure 1). The client-side framework consists of the following files located in the OnDemandPlayer folder:
- OnDemandPlayer.fla
- OnDemandPlayer.as
The FLA consists of three basic controls:
- FLVPlayback: Used for streaming FLVs (new in Flash Professional 8)
- MediaPlayback: The MP3 controller
- DataGrid: Used for connecting FLVs and MP3s with the underlying architecture
- OnDemandPlayer: A movie clip brought in pointing to ActionScript on the first frame (check the Library)
ActionScript 2.0 and MovieClip Classes
A common best practice using OOP principles for scalable applications involves attaching movie clips as classes. This is an excellent method for organizing and attaching ActionScript classes to the Stage. Peldi, one of the architects behind Breeze, describes this as a best practice. So if you are wondering how OnDemandPlayer.as is attached to OnDemandPlayer.fla, check out the Library (Figure 2).
This is comparable to using an #include file but is more manageable by simply attaching a movie clip from the Library:
attachMovie("OnDemandPlayer","mc",0);
Connecting with the Server
The file access handshake with the server is set up through a basic makeConnection function:
public function makeConnection():Void {
nc = new NetConnection();
nc.connect("rtmp://"+serverName+"/"+appName);
nc.owner = this;
nc.onStatus = function(info) {
if (info.code == "NetConnection.Connect.Success") {
owner.dir();
}
};
}
Publishing Your Folder Directory
This connects to and sends Flash Media Server the folder name from which you wish to obtain your FLVs and MP3s:
nc.call("createFileObj", null, foldername);
Getting the Stream Length
This connects with Flash Media Server to obtain the length for the FLV and MP3 lengths:
var streamlength = owner.nc.call("getStreamLength", null, stream_name);
The FLVPlayback component has stream lengths built in. To set the MP3 length in MediaPlayback and display the length in the DataGrid, it must grab the information from the FileObj main.asc file.
Obtaining the List of File Objects
On the client side, you must gather the stream names as well as other information regarding File Object in an array. This is done with the dirResult function:
private function dirResult(folderName, owner):Void {
this.onResult = function(retVal) {
for (var i = 0; i<retVal.length; i++) {
var flv_name =
(retVal[i].name).substr((retVal[i].name).lastIndexOf("/")+1);
var index = flv_name.lastIndexOf(".");
var stream_name = flv_name.substring(index + 1, flv_name.length) + ":" + owner.folderName +
"/" + flv_name.substring(0, index);
var streamlength = owner.nc.call("getStreamLength", null, stream_name);
owner.myDP_array.addItem({Name:flv_name, Length:retVal[i].streamlength,
CreationTime:retVal[i].creationTime, LastModified:retVal[i].lastModified,
Size:retVal[i].length});
}
};
Notice that the object retVal contains more than simply the stream name. It contains also creationTime, lastModified, and length (size of file).
These are just a few of the details you can gather using the List command on the server side. For a more complete list of File Objects check out Property Summary for File Class in the Flash Media Server LiveDocs.
Where to Go from Here
Using the file access and File Object features in Flash Media Server is an easy way to display content as an alternative to XML-driven data lists. The example shown in this article is a simple use case for just showing whatever media assets you have on your server. For other applications, you may want to consider combining the extensibility and organization of XML and ease of use with File Access as the perfect method for Flash Media Server on-demand applications. With this application you can easily drop your entire Flash video and MP3 media collection onto your server to stream your collection.
As learn about and come up with questions regarding Flash Media Server development, check out the Chattyfig list. This is the premier list for Flash Media Server developers and always contains informative development discussions. As a developer, I rely on this valuable resource whenever I face a tough problem. Just be careful what you ask, however, because if the answer is a simple Google's search away, they will hound you for it.
I hope this has helped you understand the new file access feature built into Flash Media Server. I wish you the best of luck with your future Flash Media Server adventures.
This article originally appeared on www.macromedia.com/devnet. Reprinted with permission.
Published February 26, 2006 Reads 18,991
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Robert Sandie
Robert Sandie interned at Macromedia as a product manager for the Flash Media Server team. He recently earned his degree in Computer Science and Business from Lehigh University in Bethlehem, Pennsylvania, where he also played football for the Mountain Hawks. Robert has a wealth of experiencing leading Flash projects and developing Flash video applications. To view his latest endeavors, catch up with him at robertsandie.com.
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Unveils LiveCycle Enterprise Suite 2 for Deployment in the Cloud
- Adobe Flex Developer Earns $100K in New York City
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Ph.D. in Twitter Anyone?
- Eolas Sues the Internet
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Special Report on the Emerging Cloud Computing Trend
- Adobe Cans Another 9% of its Workforce
- My Thoughts on Ulitzer
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Ulitzer Live! New Media Conference & Expo
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Executives Feature on Cloud Computing Expo Power Panel
- Software Flexibility in the Cloud - Part 4 of 5
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- Adobe Unveils LiveCycle Enterprise Suite 2 for Deployment in the Cloud
- Where Are RIA Technologies Headed in 2008?
- Cover Story: How to Increase the Frame Rates of Your Flash Movies
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Your First Adobe Flex Application with a ColdFusion Backend
- Adobe Flex 2: Advanced DataGrid
- i-Technology Blog: Death-Knell For "Rich Media? Hardly!
- Adobe/Macromedia - Microsoft, Look Out!
- How To Create a Photo Slide Show ...
- Adobe Flex Interface Customization - Themes, Styles, Skins
- Personal Branding Checklist
- Has the Technology Bounceback Begun?
- "Real-World Flex" by Adobe's Christophe Coenraets




































