AS3 Video Player, placed on timeline, with spinning preloader


/ Published in: ActionScript 3
Save to your folder(s)

An ActionScript3 video player placed on the stage, configurable by FlashVars. It displays a spinning loader until the video loads.

Also see http://snipplr.com/view/11606/ for another AS3 video code template
Read about AS3 video in this in-depth tutorial: http://www.republicofcode.com/tutorials/flash/as3flvplayback/


Copy this code and paste it in your HTML
  1. // send this file the flashvars: "videofile" + optional "barcolor" + optional "autoplay=false" + optional "mute=true"
  2.  
  3. import fl.video.* // to be able to refer to the properties of the FLVPlayback component
  4.  
  5.  
  6. var objFlashVars:Object = getFlashVars();
  7.  
  8. myVideo.autoPlay = true; // the FLVPlayback component instance on the stage is named myVideo
  9. myVideo.source = "http://www.mediacollege.com/video-gallery/testclips/20051210-w50s_56K.flv"; // a default video. This will be over-ridden by your value from the FlashVars
  10. myVideo.skin = getContextPath() + "SkinOverAllNoFullNoCaption.swf"; // feel free to change the skin. This will need to be placed in the same directory as the genplayer.swf
  11.  
  12. // Change settings based on FlashVars:
  13. if (objFlashVars.videofile != undefined) { myVideo.source = objFlashVars.videofile; }
  14. if (objFlashVars.barcolor != undefined) { myVideo.skinBackgroundColor = objFlashVars.barcolor; }
  15. if (objFlashVars.autoplay != undefined) { if (objFlashVars.autoplay == "false") { myVideo.autoPlay = false; } }
  16. if (objFlashVars.mute != undefined) { if (objFlashVars.mute == "true") { myVideo.volume = 0; } }
  17.  
  18. // Get rid of the loader:
  19. myVideo.addEventListener(VideoEvent.READY, myFun);
  20. function myFun(e:VideoEvent):void {
  21. spinner_mc.stop();
  22. spinner_mc.visible = false;
  23. spinner_mc.enabled = false;
  24. }
  25.  
  26. // That's it. The video should autoPlay unless you've told it not to with FlashVars.
  27.  
  28.  
  29. ////////////////////////////////////////////////////////////////////////////////////////////////
  30. // Related Functions Below, from http://snipplr.com/view/10204/as3-my-favorite-helper-functions/
  31. ////////////////////////////////////////////////////////////////////////////////////////////////
  32.  
  33. function getFlashVars():Object
  34. {
  35. return Object( LoaderInfo( this.loaderInfo ).parameters );
  36. }
  37.  
  38. function getContextPath():String
  39. {
  40. var uri:String = getLoaderURL();
  41. return uri.substring(0, uri.lastIndexOf("/")) + "/";
  42. }
  43.  
  44. function getLoaderURL():String
  45. {
  46. return this.loaderInfo.loaderURL;
  47. }

URL: http://files.getdropbox.com/u/316550/code-AS3_videoplayer.zip

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.