macromedia help home
Bookmark this page using your favorite bookmark manager

How to create a flv player without the media components

Here is a short few tips on how to create your own netstream and preload it to display FLV video's on your site.

To create a flash Flv player without using media components, first you need to make a new "video object". Open your library,left click on the upper right icon and select "new video". Now you have a video object in your library,drag it onto the stage.

Give the "video object" this instance name: my_video

Select the first frame in your timeline ( on a new layer ), open the action panel and enter the following actionscript:

  1. var connection_nc:NetConnection = new NetConnection();
  2. connection_nc.connect(null);
  3. var stream_ns:NetStream = new NetStream(connection_nc);
  4. my_video.attachVideo(stream_ns);
  5. stream_ns.play("Flv_files/"+_root.moviestatus+".flv");
  6. stream_ns.onStatus=function(infoObject){
  7. if(infoObject.code=="NetStream.Play.Stop"){
  8. stream_ns.seek(0);
  9. stream_ns.play();
  10. }
  11. };
  12.  
  13. this.createTextField("loaded_txt", this.getNextHighestDepth(), 10, 10, 160, 22);
  14. this.createEmptyMovieClip("progressBar_mc", this.getNextHighestDepth());
  15. progressBar_mc.createEmptyMovieClip("bar_mc", progressBar_mc.getNextHighestDepth());
  16. with (progressBar_mc.bar_mc) {
  17. beginFill(0x000000);
  18. moveTo(0, 0);
  19. lineTo(100, 0);
  20. lineTo(100, 10);
  21. lineTo(0, 10);
  22. lineTo(0, 0);
  23. endFill();
  24. _xscale = 0;
  25. }
  26. progressBar_mc.createEmptyMovieClip("stroke_mc", progressBar_mc.getNextHighestDepth());
  27. with (progressBar_mc.stroke_mc) {
  28. lineStyle(0, 0x000000);
  29. moveTo(0, 0);
  30. lineTo(100, 0);
  31. lineTo(100, 10);
  32. lineTo(0, 10);
  33. lineTo(0, 0);
  34. }
  35.  
  36. var loaded_interval:Number = setInterval(checkBytesLoaded, 500, stream_ns);
  37. function checkBytesLoaded(my_ns:NetStream) {
  38. var pctLoaded:Number = Math.round(my_ns.bytesLoaded/my_ns.bytesTotal*100);
  39. loaded_txt.text = Math.round(my_ns.bytesLoaded/1000)+" of
  40. "+Math.round(my_ns.bytesTotal/1000)+" KB loaded ("+pctLoaded+"%)";
  41. progressBar_mc.bar_mc._xscale = pctLoaded;
  42. if (pctLoaded>=100) {
  43. removeMovieClip(progressBar_mc);
  44. removeMovieClip(loaded_txt);
  45. clearInterval(loaded_interval);
  46. }
  47. }

Some variables have been used in this code:
stream_ns.play("Flv_files/"+_root.moviestatus+".flv");
Flv_files = the folder where the flv movies are.
moviestatus = A variable that defines wicth movie will be played(can be changed by a button for example).

That's all
Enjoy,

Author: Christophe Seynaeve. Author website
Rate this content; the results will appear next to article links in site:
You need flash player