Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite 6
  • 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
  • Government

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 / Flex Developer Center /

Using Flash media components to play video in Flex projects

by Serge Jespers

Serge Jespers
  • Adobe

Created

12 May 2008

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
componentsFlexvideo
Was this helpful?
Yes   No

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

 
Thanks for your feedback.

Requirements

Prerequisite knowledge

User Level

Intermediate

Required products

  • Flex Builder 3 (Download trial)

Sample files

  • video_flex.zip (686 KB)

Additional Requirements

Flex Component Kit for Flash CS3

  • Download

One of the things I hear a lot is that people really miss the Flash media components when they're diving into Flex. So why not use that component you love so much in your Flex projects? The Flex Component Kit for Flash CS3 has been out there for a while now and if you have all the latest updates to Flash, it's even part of your Flash CS3 authoring environment by default now. I have the feeling that people underestimate this feature and don't really appreciate the power of this yet. So I thought it was a good idea to create a little tutorial to show you how easy it is to make Flex components in Flash CS3 and in this case, how to use the Flash media components inside your Flex projects.

So we're going to create a Flex component that holds the FLVPlayback component and write a little bit of ActionScript code to make it work in Flex.

First, you need to check if your Flash CS3 authoring is up to date. If it is, your commands menu should look like this (see Figure 1):

Your commands menu
Figure 1.Your commands menu

If your Commands menu looks different, make sure you click the "Updates…" option in the Help menu to get all the latest updates.

Make a new Flash document and drag and drop the "FLVPlayback" component from the component panel to the stage (see Figure 2).

The "FLVPlayback" component
Figure 2.The "FLVPlayback" component

Make sure you specify an instance name for that component. I'm calling mine "MyPlayer" (see Figure 3).

Instance name for the component
Figure 3.Instance name for the component

Next, make a movieclip from that FLVPlayback component. I'm going to call mine "MyVideoPlayer" (see Figure 4).

Make a movie clip from the FLVPlayback component
Figure 4.Make a movie clip from the FLVPlayback component

When you've done that, go ahead and double-click the MyVideoPlayer movie clip. Create a new layer and draw a rectangle with the same size as your FLVPlayback component. Convert this into a movie clip and specify its instance name to "boundingBox". Once you use your component in Flex, it will not be visible. Flex will use this "boundingBox" movie clip to determine how big your component actually is.

By default, the FLVPlayback component will also show a player skin. If your FLVPlayback component isn't previewing a player skin, you can select the skin you want to use in the parameters panel. In my case, I'm going to select SkinOverAllNoFullNoCaption as my player skin (see Figure 5).

Select the skin you want to use in the parameters panel
Figure 5.Select the skin you want to use in the parameters panel

Also, check if the autoPlay parameter and the skinAutoHide parameter are set to "true".
Obviously you could also make your own player skin or even use the different button components. But in this case I want to keep it simple for demo purposes. Next you're going to add some ActionScript code to control the size and to set the source file. This may actually be a good time to save your FLA file. When you've done that, create a new ActionScript file (File > New… > ActionScript File). You're actually going to create an ActionScript class for your MyVideoPlayer MovieClip. Sadly, Flash CS3 doesn't give you the option to automatically make the class structure so you have to do that manually.

Just copy and paste this code snippet to start with:

package { import mx.flash.UIMovieClip; import flash.display.MovieClip; public dynamic class MyVideoPlayer extends UIMovieClip { public function MyVideoPlayer() { super(); } } }

Go ahead and save that ActionScript file in the same folder as your FLA and name it "MyVideoPlayer.as". Now go back to your FLA and right-click the MyVideoPlayer movie clip in the Library panel and select "Linkage". You're actually going to link the class file that you just created to this movie clip (see Figure 6).

Link the ActionScript class file to the movie clip
Figure 6.Link the ActionScript class file to the movie clip

When you check the "Export for ActionScript" box, your window should automatically look like this (see Figure 7):

The Linkage Properties window
Figure 7.The Linkage Properties window

To verify that you saved and named everything correctly, click the "Edit class definition" icon:

file

This should bring you back to the ActionScript class. if it doesn't, make sure the name is correct and that you saved the ActionScript file in the same folder as your FLA file. Don't forget to click "OK" to save your linkage settings.

Now have another look at the Class structure. As you can see, we're going to extend the UIMovieClip class. This class has all the methods a normal Flex component has. That means I can automatically use getters and setters like any other Flex components have. So the first function I'm going to create is a setter function to specify the video source file url.

public function set source(MyVid:String):void{ MyPlayer.play(MyVid); }

No rocket science here. I just tell the FLVPlayback component inside my movie clip to play the video file I will pass it. I also want to be able to size the component to whatever size I want. You could use the standard width and height setters but I'm not going to do that. I'm actually going to override these setters so I can set the width and height of the FLVPlayback component instead of the whole component. If I wouldn't do that, my player skin would become distorted and stretched. So go ahead and add these lines of code:

override public function set width(w:Number):void{ MyPlayer.width = w; } override public function set height(h:Number):void{ MyPlayer.height = h; }

Your class file should now look like this:

package { import mx.flash.UIMovieClip; import flash.display.MovieClip; public dynamic class MyVideoPlayer extends UIMovieClip { public function MyVideoPlayer() { super(); } public function set source(MyVid:String):void{ MyPlayer.play(MyVid); } override public function set width(w:Number):void{ MyPlayer.width = w; } override public function set height(h:Number):void{ MyPlayer.height = h; } } }

Now we are ready to "bake" our Flex component. Select the MyVideoPlayer movie clip in the library window and then select the "Convert Symbol to Flex Component" command in the Commands menu. Chances are Flash will give you a little popup window telling you that your frame rate doesn't match the default frame rate that Flex uses (see Figure 8).

The frame rate popup window
Figure 8. The frame rate popup window

Just go ahead and click "OK". In the Output window, Flash will ask you to publish your file:

Select File > Publish to create the SWC file for use in Flex.

Obviously, this is what you want to do next.

When you did that, Flash created a couple of files for you (see Figure 9):

The files Flash created for you
Figure 9. The files Flash created for you

The SWC file is the one we will be using in Flex. Open up Flex Builder 3 and create a new project. The first thing we need to do is to add our component to the Flex library so it knows that this is now available. In Flex Builder 3 it's as easy as just copying the SWC file into the libs folder of your project. You can even drag it in there straight from your Finder or Explorer window.

If you've done that, you also need to add the player skin you're using. This goes into the src folder. So go ahead and drag "SkinOverAllNoFullNoCaption.swf" to the src folder of your Flex project. Your project folder should now look like this (see Figure 10):

Project folder structure
Figure 10. Project folder structure

Now open the main MXML file of your project. In my case it's called "FlashFlexMarriage.mxml". If your Flex Builder is in Design view, switch to Code view. When you start typing "MyVideoPlayer", you will see that Flex Builder now knows your component and gives you codecompletion for it. When you hit Enter, the "local" namespace will be added to the application descriptor and your component will be added. Now you can add the source of your FLV.

<local:MyVideoPlayer source="http://www.helpexamples.com/flash/video/lights_short.flv"/>

Go ahead and run this project. Your video should start playing instantly.

I think it would be nicer to see this video a bit bigger and because we added the width and height setters, we can do that without distorting our player skin.

<local:MyVideoPlayer source="http://www.helpexamples.com/flash/video/lights_short.flv" width="640" height="480" x="0" y="0" />

When you run it again, you'll see that the player skin is still proportioned in the same way.

Where to go from here

You have now successfully created a Flex component in Flash. Obviously, this is just an example and you can do so much more but I think this shows how powerful the combination of Flash and Flex can be.

Visit the Flex Developer Center and Flash Developer Center for more developer resources.

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

More Like This

  • Building an icon-checkbox component with Flex 3
  • What's new in Flex 4.6 SDK and Flash Builder 4.6
  • Introducing Adobe Flex 4.6 SDK
  • Building a video application with Flex Builder
  • Building interactive maps with Flex
  • Building a simple dashboard using Flex 3 with ILOG Elixir
  • Creating Flex components
  • Creating components and enforcing separation of concerns with Flex
  • Defining and using new skin parts in a Spark skin
  • AdvancED Flex Application Development excerpt: Working with video

Tutorials & Samples

Tutorials

  • Flex mobile performance checklist
  • Flex and Maven with Flexmojos – Part 3: Journeyman
  • Migrating Flex 3 applications to Flex 4.5 – Part 4

Samples

  • Twitter Trends
  • Flex 4.5 reference applications
  • Mobile Trader Flex app on Android Market

Products

  • Adobe Creative Cloud
  • Creative Suite 6
  • 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 (Updated) | Cookies

Ad Choices