Posted By

Winkyboy on 07/23/09


Tagged

video flashvars as3 FLVPlayback


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

tspitzr
mitien
letmein_xxi


AS3 Video Player, placed on timeline, with spinning preloader


 / Published in: ActionScript 3
 

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

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/

  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. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Dene7 on October 27, 2010

Hi! Fantastic post! I just started to learn Flash and I found it's so helpful! There is a line .. import caurina.transitions.Tweener; // don't forget to install this.... Could you give more details what do I need to install?

Many Thanks!

Posted By: Winkyboy on February 16, 2011

Thanks - and I apologize for answering so late in the game. I'm sure you've figured it out by now, but that's the Tweener library (http://code.google.com/p/tweener/) ((Either I have notifications disabled, or Snipplr doesn't send email when people write comments... ))

You need to login to post a comment.