Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 14th, 2012  |  syntax: None  |  size: 3.12 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. external interface and swfobject.js issue
  2. $(function(){
  3.      //the video player shouldn't be built until the user presses the div with 'video-btn' class
  4.     $('.video-btn').click(function(){
  5.          var videoplayer = new VideoPlayer();
  6.          videoplayer.addVideoPlayer();
  7.          //external interface function
  8.          videoplayer.player.loadVideo();
  9.     });
  10. });
  11.        
  12. //inside of VideoPlayer object definition
  13. this.addVideoPlayer = function(){
  14.      var that = this;
  15.      $('body').append('<div id="no-flash"></div>');
  16.  
  17.      //uses swfobject.js to replace the div i just appended with the flash object
  18.      //This works fine.  the flash object replaces the div as intended
  19.      that.embedFlashObject();
  20.      //that.player is (supposed to be) a reference to flash object
  21.      that.player = that.getFlashObject();
  22. };
  23.  
  24. this.embedFlashObject = function(){
  25.      var that = this;
  26.  
  27.      //set up all the variables to pass to swfobject.embedSWF
  28.  
  29.      //this method removes my div and replaces it with an object element that contains the swf file
  30.      //the object tag gets an id which is specified.  Let's assume it's 'vp'
  31.      swfobject.embedSWF(swfFile, 'no-flash', width, hieght, '9.0.0', ... );
  32. };
  33.  
  34. this.getFlashObject = function(){
  35.      var that = this;
  36.  
  37.      //this method returns the flash object to make external interface calls on
  38.      //this the method prescribed by swfobject api  
  39.      var videoObj = swfobject.getObjectById('vp');
  40.      if(typeOf videoObj == 'undefined')
  41.      {
  42.           //check if useragent string is IE
  43.           var isIE = navigator.userAgent.match(/MSIE/i);
  44.           videoObj = isIE ? window['vp'] : document['vp'];
  45.      }
  46.      return videoObj;
  47. };
  48.        
  49. //inside of VideoPlayer object definition
  50. this.addVideoPlayer = function(){
  51.  
  52.     var that = this;
  53.  
  54.     if (swfobject.hasFlashPlayerVersion("9")){
  55.  
  56.         $('body').append('<div id="no-flash"></div>');
  57.  
  58.         //For legibility
  59.         var swfdata = {
  60.             data: swfFile,
  61.             width: width,
  62.             height: height
  63.         };
  64.  
  65.         var params = { bgcolor: color };
  66.  
  67.         var id = 'no-flash';
  68.  
  69.         that.player = swfobject.createSWF(swfdata, params, id);
  70.  
  71.     }
  72.  
  73. };
  74.        
  75. //inside of VideoPlayer object definition
  76. this.addVideoPlayer = function(){
  77.     var that = this;
  78.     if (swfobject.hasFlashPlayerVersion("9")){
  79.         $('body').append('<div id="no-flash"></div>');
  80.         that.player = swfobject.createSWF({data: swfFile, width: width, height: height}, {bgcolor: color}, 'no-flash');
  81.     }
  82. };
  83.        
  84. swfobject.embedSWF("/Flash/Player.swf", "flash", "100%", "100%", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes, function (e) {
  85.     document.getElementById("flash").loadMedia();
  86. });
  87.        
  88. var videoObj = swfobject.getObjectById('vp');
  89.   if(typeOf videoObj == 'undefined')
  90.   {
  91.        //check if useragent string is IE
  92.        var isIE = navigator.userAgent.match(/MSIE/i);
  93.        videoObj = isIE ? window['vp'] : document['vp'];
  94.   }
  95.   return videoObj;
  96.        
  97. if(typeOf videoObj == 'undefined')
  98.       {
  99.            //check if useragent string is IE
  100.            var isIE = navigator.userAgent.match(/MSIE/i);
  101.            videoObj = isIE ? window['vp'] : document['vp'];
  102.       }