views:

23

answers:

2

Hi, I have a page with a flash chart to display. First, I make a separate AJAX call to grab the chart data, and then process it in javascript and call the flash object functions like this:

var flashObj = YAHOO.util.Dom.get(chartContainer);
if (!YAHOO.env.ua.ie) {
    flashObj = flashObj.getElementsByTagName("embed")[0];
}
flashObj.SetSettingOption(dataXml.xml);
flashObj.SetAndParseData(dataXml.xml);
flashObj.Draw();

However, in Firefox I get the error "flashObj.SetSettingOption is not a function". I do not encounter this in IE8. Is this because the flash object is not fully loaded? But then on subsequent visits to the page, the flash object should be cached, but the same error appears.

Edit: Also here part of the html

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="MyChart" width="760"
    height="455" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"&gt;
    <param name="movie" value="../flash/MyChart.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffffff" />
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="wmode" value="transparent" />
    <embed src="../flash/MyChart.swf" quality="high" bgcolor="#ffffff" width="760"
        wmode="transparent" height="455" align="middle" play="true" loop="false"
        allowscriptaccess="sameDomain" type="application/x-shockwave-flash" 
        pluginspage="http://www.adobe.com/go/getflashplayer"&gt;
    </embed>
 </object>

Thanks in advance for any help!

+1  A: 

Try to use "document" instead of "flashObj", like this:

if (!YAHOO.env.ua.ie) {
    flashObj = document.getElementsByTagName("embed")[0];
}

If it doesn't work, so you could try using document.embeds["YOUR_FLASH_OBJECT_ID_HERE"] only for Firefox, like this:

if (!YAHOO.env.ua.ie) {
    flashObj = document.embeds.YOUR_FLASH_OBJECT_ID_HERE;
}

Take a look at this documentation, it might help you: Referencing Flash Movie

Good luck!

Fabiano
Thanks for the suggestions! It did not work for me though. I do not think it is an issue with how I am grabbing the <embed> in firefox.
weiy
You're welcome =). Have you tried your code using the $(document).ready event from jquery? It loads everything, including flash objects, before executing a javascript statement.
Fabiano
+1  A: 

Is this because the flash object is not fully loaded?

Yes, that frequently happens with Flash.

But then on subsequent visits to the page, the flash object should be cached, but the same error appears.

Probably not. The flash object needs to do set up its external interface. This takes some time, no matter if the .swf file itself is cached or not.

Usually this is solved by using a callback function in ActionScript, something like

ExternalInterface.call('flashLoaded');

or similar.

Pumbaa80
Ah, I did not know that about flash object set up. I delayed the AJAX call for data a little bit, and it is now displaying. I will now try to do it the more correct way using callback from as3. Thanks!
weiy