More in this section

Forums / Developing with Sitefinity / Find flash object from Master Page/Sitefinity

Find flash object from Master Page/Sitefinity

7 posts, 0 answered
  1. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    05 Aug 2007
    Link to this post
    Hi Sitefinity users -

    I have a strange problem I am unable to locate the Flash object in order to call Flash Action Script functions from JavaScript. The JavaScript to embed the flash looks like this:

     <script type="text/javascript">  
        if (AC_FL_RunContent == 0) {  
            alert("This page requires AC_RunActiveContent.js.");  
        } else {  
            AC_FL_RunContent(  
                'codebase''http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',  
                'width''1',  
                'height''1',  
                'src''http://localhost:1158/site1/Files/flash/backgroundPlayer',  
                'quality''high',  
                'pluginspage''http://www.macromedia.com/go/getflashplayer',  
                'align''middle',  
                'play''true',  
                'loop''true',  
                'scale''showall',  
                'wmode''window',  
                'devicefont''false',  
                'id''backgroundPlayer',  
                'bgcolor''#ffffff',  
                'name''backgroundPlayer',  
                'menu''true',  
                'allowFullScreen''false',  
                'allowScriptAccess','sameDomain',  
                'movie''http://localhost:1158/site1/Files/flash/backgroundPlayer',  
                'salign''' 
                ); //end AC code  
        }  
        </script> 

    The JavaScript to find the flash object looks something like this.

     function playAudio() {  
            var callResult = getFlashMovie("backgroundPlayer").backgroundPlayerPlayAudio('http://localhost:1158/site1/files/media/floggingMolly.mp3', 8000, true, true);  
        }  
     
    function getFlashMovie(movieName) {  
            var isIE = navigator.appName.indexOf("Microsoft") != -1;  
            return (isIE) ? window[movieName] : document[movieName];       
        } 

    It works fine in Firefox, but oddly enough does not work in IE7. Does anyone know how to modify the JS to get this bad boy to work.

    Sincerely,

    Ben
  2. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    05 Aug 2007
    Link to this post
    Perhaps it is the function that writes the flash object to page to begin with that is failing and the window[movieName] is working?

    Sincerely,

    Ben
  3. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    07 Aug 2007
    Link to this post
    Hello Ben,

    Try to use the following function to retrieve the Flash movie:

    function getFlashMovieObject(movieName) 
      if (window.document[movieName])  
      { 
          return window.document[movieName]; 
      } 
      if (navigator.appName.indexOf("Microsoft Internet")==-1) 
      { 
        if (document.embeds && document.embeds[movieName]) 
          return document.embeds[movieName];  
      } 
      else // if (navigator.appName.indexOf("Microsoft Internet")!=-1) 
      { 
        return document.getElementById(movieName); 
      } 

    Also you could have a look at this article http://www.permadi.com/tutorial/flashGetObject/ that discusses several approaches for referencing a Flash movie depending on the browser.


    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    07 Aug 2007
    Link to this post
    From what I understand this had to do with the way that IE defines objects after the page is loaded. Also you will notice that you cannot do this inside of a form tag. The solution was an additional script that works with the SWFObject. If you have functions in Action Script 3 that you want to run when the page loads. The window.addEvent(load, myFunction); from mootools does not work because the flash object has not been defined yet. So any onload functions need to be called by the flash itself. Hence the addition of Flash variables. You can see a working example of this at this Alighten Sitefinity project.

    The script to get this working looks like:

    <script src="/files/scripts/swfobject.js" type="text/javascript"></script><script src="/files/scripts/swfformfix2.js" type="text/javascript"></script> <div id="flashcontent"><a href="swfobject.html?detectflash=false"></a></div><script type="text/javascript">  
                                              window["backgroundPlayer"] = new Object();  
                                                var so = new SWFObject("/Files/flash/backgroundPlayer.swf""backgroundPlayer""5""5""9""#ffffff");  
    so.addVariable("FileName""/Files/media/Spanish_Passion_full_mix.mp3");  
    so.addVariable("BufferTimeBeforePlay", 8000);  
    so.addVariable("CheckPolicyFile"true);  
    so.addVariable("Repeat"true);  
            so.write("flashcontent");  
     
    function getFlashMovie(movieName) {  
              
            var isIE = navigator.appName.indexOf("Microsoft") != -1;  
            if (isIE) {              
                return window[movieName];              
            } else {  
                return document[movieName];     
            }     
        }  
         function toggleAudio() {  
            var callResult = getFlashMovie('backgroundPlayer').backgroundPlayerToggleAudio();    
        }  
        function playAudio() {  
            var callResult = getFlashMovie("backgroundPlayer").backgroundPlayerPlayAudio('/Files/media/Spanish_Passion_full_mix.mp3', 8000, truetrue);  
        }  
     
        </script> 

    Notice the window["backgroundPlayer"] = new Object(); above the SWFObject as well as the call to swfformfix2.js. The content above was added to the Generic Content. Information and download for swffomfix2.js can be found at Steve Kamerman's Blog.


  5. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    30 Mar 2009
    Link to this post
    Hi bnye, others,

    I'd like to know what kind of player you are using on your site? I'm looking for a simple mp3 player that users can turn on or off using a simple button (Play/Stop).

    Problem is that SF uses postbacks, so I suppose there is no way I can implement background music on a Sitefinity website?

    Any idea?

    Thanks,
    Daniel
  6. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    03 Apr 2009
    Link to this post
    Check out the one that I built here. It's just a home made flash player that uses an 2 images and javascript to control play.

    http://www.patiosource.com/webfolio.aspx

    If it works for you  I am happy to give you my action script and javascript code if I can find it.

    Sincerely,

    Ben
  7. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    03 Apr 2009
    Link to this post
    PS Click the music note to start and stop.

    Ben
Register for webinar
7 posts, 0 answered