views:

171

answers:

2

Hi All,

I currently have an application that calls creates and displays charts from various objects' data using JS. However, I'm having some severe issues. Can someone please explain why the following code works just fine when statically inserted into a page, but when used via rjs "page.replace_html my_div_id" it removes EVERYTHING ELSE on the page:

    <script language="JavaScript" type="text/javascript">
        <!--
        if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
         alert("This page requires AC_RunActiveContent.js.");
        } else {
         var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
         if(hasRightVersion) { 
          AC_FL_RunContent(
           'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
           'width', '800',
           'height', '500',
           'scale', 'noscale',
           'salign', 'TL',
           'bgcolor', '#777788',
           'wmode', 'opaque',
           'movie', 'charts',
           'src', 'charts',
           'FlashVars', 'library_path=xmlswfitems/charts_library&xml_source=xmlcharts/M1 Building One', 
           'id', 'my_chart',
           'name', 'M1 Building One',
           'menu', 'true',
           'allowFullScreen', 'true',
           'allowScriptAccess','sameDomain',
           'quality', 'high',
           'align', 'middle',
           'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
           'play', 'true',
           'devicefont', 'false'
           ); 
         } else { 
          var alternateContent = 'This content requires the Adobe Flash Player. '
          + '<u><a href=http://www.macromedia.com/go/getflash/&gt;Get Flash</a></u>.';
          document.write(alternateContent); 
         }
        }
        // -->
    </script>

...also, it completely fails with IE. My only leads are from Safari ("unmatched embed tag"), Firefox (browser pretends chart never loads even though it has), IE (non-specific prototype.js error). FYI, I'm using XML/SWF Charts. I'm writing this code from scratch as I have needs not met by the existing/outdated SWFCharts library so please don't suggest solutions involving that particular library.

Best.

+1  A: 

Use a standard library like SWFObject to embed your flash. It takes care of all the crossbrowser quirks for you and let's you do both static and dynamic publishing with regular html to fall back on if the user does not have flash.

grapefrukt
A: 

AC_FL_RunContent uses document.write to generate the <object>/<embed> tags, which, if called after the page is completely loaded, replaces the entire contents of the page.

You will probably need to use SWFObject; as far as I know, it doesn't use document.write so it should work anytime.

Matthew Crumley