Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / Adobe Media Server Developer Center /

Beginner's guide to using ActionScript 3.0 with Flash Media Server 3.5

by Tom Green

Tom Green
  • tomontheweb.ca

Content

  • Streaming from the vod folder
  • Creating a streaming video application

Modified

12 January 2009

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScriptFlash Media Server 3H.264streamingvideo
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Requirements

User level

Beginning

Required products

  • Flash Media Server 3 (Download trial)
  • Flash Professional CS4 (Download trial)

Sample files

  • beginner_as3_fms3.zip (32392 KB)

This article is the third in my series of beginning-level Flash Media Server 3.5 tutorials. This particular tutorial shows you how to use ActionScript 3.0 to stream an H.264 video from the vod folder, and then stream that same video from an application.

Here are all the articles in the series:

  • Part 1: Installing Flash Media Server 3.5
  • Part 2: Streaming video with Flash Media Server 3.5
  • Part 3: Using ActionScript 3.0 with Flash Media Server 3.5
  • Part 4: Security features in Flash Media Server 3.5
  • Part 5: Streaming audio through Flash Media Server 3.5
  • Part 6: Streaming live video with Flash Media Server 3.5
  • Part 7: Dynamic streaming with Flash Media Server 3.5

Streaming from the vod folder

First, I'll show you how to stream H.264 video from the vod folder using ActionScript:

  1. Download the files used in this article. The MP4 file is one created by the Film and Television Production students at the college where I work.
  2. When you unzip the file, copy the Vultures.mp4 file to the Clipboard.
  3. Navigate to C:\Program Files\Adobe\Flash Media Server 3.5\applications. Inside this folder you will see a folder named vod. Open it.
  4. Open the media folder and paste the video on the clipboard into this folder.
  5. Close the open window.

Nothing new here. If you have been following this series, you know the vod folder is seen as a publishing point. To date, all we have done is to simply set the Content Path of the FLVPlayback component to rtmp://localhost/vod/mp4:Vultures and the video plays.

In this tutorial we are going to skip using the FLVPlayback component and, instead, feed the video from the vod folder into a video object on the Stage. Here's how:

  1. Open the H264_StreamVOD.fla file in the sample download. For those of you who have migrated to Flash CS4 Professional, the FLA files can be found in the FlashCS4 folder.
  2. When the file opens, you will see I have created the interface for you.
  3. The video object with the instance name of "myVideo" is found in the video layer. All you need to do now is to "wire this project up" with ActionScript 3.0. Select the first frame in the actions layer and press the F9 key to open the Actions panel.

    Note: The video object you use should match the dimensions and/or aspect ratio of the FLV or MP4 file it plays. The default size for a video object on the stage is 160 × 120. This is a 4:3 aspect ratio and works with FLV files that use this ratio. If you are using HD content that uses the common 16:9 aspect ratio, failing to resize the video object will result in a distorted video when it appears in the video object.

  4. Click once in the Script pane and enter the following:
var nc:NetConnection = new NetConnection(); nc.connect("rtmp://localhost/vod"); var ns:NetStream = new NetStream(nc);

The first line sets up the NetConnection and the second line tells Flash the NetConnection is to the vod folder in FMS 3.5. If you have been using a video object to progressively download a file, you will notice the connection string is the path to the vod folder on the FMS 3.5 server and not a "null" string. In this example, you are working locally with the developer version of FMS 3.5. If you have a commercial account, localhost will be replaced with an actual RTMP address (which is a series of numbers) and there might, or might not, be a path to the vod folder, depending upon your ISP's unique requirements.

With the connection made and the NetStream established, it's time to do a little bit of housekeeping and make sure you have successfully connected to the server—also to increase the amount of the video that will be buffered before it streams. Here's how:

  1. Press the Return/Enter key twice and enter the following code:
nc.onStatus = function(ncObj:Object) { trace(ncObj.code); if (ncObj.code == "NetConnection.Connect.Success") { ns.setBufferTime(2);

The code starts by using an onStatus event to check if you have successfully connected to FMS 3.5. You do this by by capturing the code string ("NetConnection.Connect.Success") sent to Adobe Flash Player when the SWF connects to FMS 3.5. The trace statement will open the Output panel and actually display that code (see Figure 1) if there has been a successful connection.

Connection code
Figure 1. Connection code in the Output panel

If the connection is successful, the setBufferTime() method of the NetStream class is used to put two seconds of video into the buffer. The default buffer value is 0.1 seconds; it's up to you how big a buffer to set.

  1. Press the Return/Enter key and enter the remaining code:
myVideo.attachVideo(ns); ns.play("mp4:Vultures"); } };

The first line attaches the NetStream to the video object with the instance of myVideo on the Stage. The second uses the NetStream play() method to actually play the video. It is important to note that you need to include the media type, mp4: (including the colon), in the string. Also, because you are using FMS 3.5, you don't need to add the extension to the video's name.

Note: If you were using an FLV file instead, the play string would be "Vultures". You don't need to add the media type for FLV files.

  1. Save and test the movie. There will be a slight delay as two seconds of the video is added to the buffer. When it finishes buffering, you get to visit a nest of baby turkey vultures, as shown in Figure 2.
Video showing nest of baby turkey vultures
Figure 2. Cute little critters, aren't they?

Creating a streaming video application

So far, in this series, you have essentially been operating on autopilot and letting FMS 3.5 automatically feed a video stream from the vod folder into the FLVPlayback component or a video object on the Stage. There will come a time when the vod folder is more of a hindrance than an asset, however. Also, the vod folder is a feature of Flash Media Streaming Server. If you are using Flash Media Interactive Server, you will need to know how to create an application that plays from this server.

Actually, it is not terribly mysterious to use, but if you are new to FMS 3.5 it can be a bit confusing. To start with, your publishing point is not a vod folder; it is your applications folder. This folder is placed in the applications folder of FMS 3.5 but it is named by you.

The next big difference is the use of an instance. This has nothing to do with ActionScript. An instance is a specific folder named _definst_ that you must create and into which you place the video or audio files.

In addition, there is usually an .as file in the application folder that contains some relatively simple server-side code. Take a look at what I am talking about:

  1. Inside the download folder is a folder called Exercise. Open it. Inside is a folder named BabyVultures. This is the application you will be using.
  2. Open this folder and you will see a folder named streams and a file named main.asc (see Figure 3). This file must be named main.asc; it contains the server-side code that makes stuff work.

    Note: I would like to thank my colleague Lisa Larson-Kelley for the use of this particular main.asc file.

Basic folder structure for an FMS application
Figure 3. Basic folder structure for an FMS application

An .asc file is created by selecting ActionScript Communication File from the Flash Start Panel in Flash CS4 Professional (see Figure 4) or by selecting File > New and selecting ActionScript Communication File in the New Document dialog box.

Creating an ActionScript communication file
Figure 4. Creating an ActionScript communication file in the Flash CS4 start screen
  1. Open the main.asc file and you will see how simple this server-side code really is:
application.onConnect = function(p_client) { this.acceptConnection(p_client); }

All that this code says is that when the movie start playing, the FMS 3.5 server is ready to accept the connection. This is an extremely simple example of a main.asc file. As you start moving into the realm of shared objects and even the use of custom components, this code can become very complex and run hundreds of lines.

  1. Close the open Flash document and open the streams folder. Inside the streams folder is the _definst_ folder. This is where the media gets placed. In this case, if you open _definst_, you will find a copy of the Vultures.mp4 file.

Now that you know how these things are structured, it's time to put your new knowledge to good use and stream the video:

  1. Open the applications folder, C:\Program Files\Adobe\Flash Media Server 3.5\applications, and copy the BabyVultures folder from the Exercise folder to the applications folder. You have just created an application named BabyVultures whose path is C:\Program Files\Adobe\Flash Media Server 3.5\applications\BabyVultures. Now all you need to do is to "wire up" the application.
  2. Double-click the H264_StreamApp.fla file in the Exercise folder to open it in Flash CS4 Professional.
  3. Click once in the first frame of the actions layer and open the Actions panel.
  4. When the Actions panel opens, click once in the Script pane and enter the following code:
var nc:NetConnection = new NetConnection(); nc.connect("rtmp://localhost/BabyVultures"); var ns:NetStream = new NetStream(nc);

The big difference from the previous example is in the NetConnection string in line 2. The publishing point has changed from the vod folder, which you have used in all examples in this series, to BabyVultures, which is the application.

Note: If you want to add a degree of security or digital rights management (DRM) to this file, change rtmp to rtmpe and you will automatically encrypt the stream.

  1. Press the Return/Enter key twice and enter the remaining code:
nc.onStatus = function(ncObj:Object) { trace(ncObj.code); if (ncObj.code == "NetConnection.Connect.Success") { ns.setBufferTime(2); myVideo.attachVideo(ns); ns.play("mp4:Vultures"); } };

If you test the movie in Flash at this point (see Figure 5), the video will play. The great thing about the Flash Media Server is that it is "smart." When the connection is made, it automatically looks for a streams folder. When it finds the folder it then thinks, "Ha! The video found in the ns.play() method is in the _definst_ folder!" It immediately scoots into that folder, finds the video, and tosses it onto the stream.

The code and the application it runs
Figure 5. The code and the application it runs

Where to go from here

Now that you know how to play video through an application you create on the FMS server, you might want to expand your knowledge. The best place to start is right here by checking out these articles (currently still focused on FMS 3):

  • Scaling and securing streaming media applications with Flash Media Server (Lisa Larson-Kelly)
  • New buffering strategies in Flash Player and Flash Media Server (Fabio Sonnati)

The next article in this series shows you how to encrypt your web video streams and set up SWF verification in Flash Media Server 3.5.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Encoding live video to H.264/AVC with Flash Player 11
  • Beginner's guide to streaming audio through Flash Media Server 3.5
  • Beginner's guide to dynamic streaming with Flash Media Server 3.5
  • Streaming AAC/MP3 files with Flash Media Server 3
  • Beginner's guide to installing Flash Media Server 3.5
  • Beginner's guide to streaming live video with Flash Media Server 3.5
  • Creating a video player using the state design pattern and ActionScript 3.0
  • Beginner's guide to streaming video with Flash Media Server 3.5
  • Protecting online video distribution with Adobe Flash media technology
  • Live dynamic streaming and DVR for non-developers

Tutorials & Samples

Tutorials

  • Implementing late-binding audio with Adobe Media Server for HTTP Dynamic Streaming and HTTP Live Streaming
  • Troubleshooting hang/crash issues in Adobe Media Server
  • Attaching alternate audio tracks using OSMF

Samples

  • Best practices for real-time collaboration using Flash Media Server
  • Understanding live DVR – Part 2: Using DVRCast with Flash Media Live Encoder 3
  • Understanding live DVR – Part 1: Implementing a live DVR player

Flash Media Server Forum

More
05/22/2013 AMS 5 VOD streaming to Android
05/22/2013 Using UNC path from Client in VOD application
05/21/2013 f4mconfig tool - cant run it
05/21/2013 Recorded Webcam to IOS Device

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement