How to Use AS3 FLV Player

Written by mark stansberry
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Use AS3 FLV Player
Use Flash's AS3 and the Flash FLVPlayback video player component to turn your website into a cinema. (Hemera Technologies/AbleStock.com/Getty Images)

Video is one way to open up a whole new world for your website. Videos for tutorials, advertising and product briefs, as well as general Web television, are just a few of the Web applications that you can implement with a knowledge of Flash video. Playing videos within a Flash-based Web environment is easy with Flash's FLV component. With a few ActionScript 3 (AS3) Flash Programming Language lines of code, you can use the component to load different movies, stop and start a video, and rewind a video to where you want to start playing it again.

Skill level:
Moderate

Other People Are Reading

Things you need

  • Adobe Flash Professional (Versions CS3, CS4 and CS5)

Show MoreHide

Instructions

  1. 1

    Start the Flash program. Click "New" from the File menu on the main Flash menu bar. Click the file type "Flash File(ActionScript 3.0)" from the New Document dialogue box that appears. Click "OK" to close the dialogue box.

  2. 2

    Click the "Components" option from the Window menu. Click and the drag the FLVPlayer component from the component library to the Flash stage so that the flash video class will load when the program starts. Press the "Delete" key on your keyboard to delete the FLVPlayback component.

  3. 3

    Select the "Actions" option from the Window menu on the main Flash menu bar to open the Actions editor. Position your mouse cursor on the first line of the Actions editor. Click your mouse button, and type in the code below to import the Flash video classes needed for the FLVPlayback component to work in the Flash environment.

    import fl.video.*;

  4. 4

    Type the code below, starting at the next line in the Actions editor, to create an instance of the FLVPlayback component and place it on the stage at the stage coordinates (25,50).

    var my_FLVPlybk = new FLVPlayback();

    my_FLVPlybk.x = 25;

    my_FLVPlybk.y = 50;

  5. 5

    Type the code below, starting at the next line in the Actions editor, to select the water.flv video file from the example.com website to play in the FLVPlayback component and place the component on the stage when the Flash movie plays.

    my_FLVPlybk.source = "http://www.helpexamples.com/flash/video/water.flv";

    add Child(my_FLVPlybk);

  6. 6

    Type the code below, starting at the next line in the Actions editor, to create and place an instance of a MovieClip object that is drawn with a pixel line width of 4 pixels, is filled with the colour red, is the shape of a rectangle (positioned at stage coordinates [350,200] with a width of 50 pixels and a height of 20 pixels), and will call a function that will stop the video when the MovieClip object(myButton) is clicked with the mouse.

    var myButton:MovieClip = new MovieClip();

    myButton.graphics.lineStyle(4);

    myButton.graphics.beginFill(0xFF0000);

    myButton.graphics.drawRect(350, 200, 50, 20);

    myButton.graphics.endFill();

    addChild(myButton);

    myButton.addEventListener(MouseEvent.CLICK, button_fn);

    function button_fn(e:MouseEvent): void {

    my_FLVPlybk.stop();
    

    };

  7. 7

    Type the code below, starting at the next line in the Actions editor, to create and place an instance of a MovieClip object that is drawn with a pixel line width of 4 pixels, is filled with the colour green, is the shape of a rectangle (positioned at stage coordinates [350,250] with a width of 50 pixels and a height of 20 pixels), and will call a function that will play the video when the MovieClip object(myButton1) is clicked with the mouse.

    var myButton1:MovieClip = new MovieClip();

    myButton1.graphics.lineStyle(4);

    myButton1.graphics.beginFill(0x00FF00);

    myButton1.graphics.drawRect(350, 250, 50, 20);

    myButton1.graphics.endFill();

    addChild(myButton1);

    myButton1.addEventListener(MouseEvent.CLICK, button1_fn);

    function button1_fn(e:MouseEvent): void {

    my_FLVPlybk.play();
    

    };

  8. 8

    Copy and paste the code below into the Actions editor if you want the video player program to not have any syntax errors and to run correctly the first time.

    import fl.video.*;

    var my_FLVPlybk = new FLVPlayback();

    my_FLVPlybk.x = 25;

    my_FLVPlybk.y = 50;

    my_FLVPlybk.source = "http://www.helpexamples.com/flash/video/water.flv";

    add Child(my_FLVPlybk);

    var my Button:MovieClip = new MovieClip();

    myButton.graphics.lineStyle(4);

    myButton.graphics.beginFill(0xFF0000);

    myButton.graphics.drawRect(350, 200, 50, 20);

    myButton.graphics.endFill();

    add Child(myButton);

    myButton.addEventListener(MouseEvent.CLICK, button_fn);

    function button_fn(e:MouseEvent): void {

    my_FLVPlybk.stop();
    

    };

    var myButton1:MovieClip = new MovieClip();

    myButton1.graphics.lineStyle(4);

    myButton1.graphics.beginFill(0x00FF00);

    myButton1.graphics.drawRect(350, 250, 50, 20);

    myButton1.graphics.endFill();

    add Child(myButton1);

    myButton1.addEventListener(MouseEvent.CLICK, button1_fn);

    function button1_fn(e:MouseEvent): void {

    my_FLVPlybk.play();
    

    };

  9. 9

    Click the "TestMovie" option in the Control menu on the main Flash menu bar to load the video at example.com and play the video on the Flash stage. Click the red button to stop the video from playing, and then click the green button to continue playing the video. Click the green button again to play the video again after the video has ended.

Tips and warnings

  • If your video doesn't play, check if the link specified in the AS3 code is still valid. If not, find another video to link to, or use one of your own FLV video files. If you don't drag the FLVPlayback component to the stage, you will get an error when the program compiles. If you leave the FLVPlayback component on the stage (you don't delete it), the default video component skins will interfere with the viewing of the video.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.