views:

37

answers:

2

I have a percent gauge dashboard widget implemented as an SWF movie. I am using jQuery in my JSP to achieve some AJAX update capability. For now, I am simply trying to set the value that displays on the gauge with the SetVariable() function in the code below. This cannot be done as an initial flashvar by design of the creator of the gauge (for which I do not have the source).

Problem is that both IE and FireFox complain that SetVariable is not a supported function.

Can anyone suggest a better approach to achieve this?

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!DOCTYPE html>
<html>
    <head>
        <title>Insert your title</title>
        <script type="text/javascript" src="js/jquery-1.4.2.js"></script>
        <script type="text/javascript" src="js/jquery.swfobject.1-1-1.js"></script>
        <script type="text/javascript">
            var pct_gauge = $.flash.create ({
                swf: 'flash/percentgauge.swf',
                width: 200,
                height: 200,
                wmode: 'transparent',
                play: true,
                flashvars: {
                    title: 'Percent Contracts Valid'
                }
            });

            $(document).ready(function() {
                $('#pct_gauge').html(pct_gauge);
            //    $('pctgauge').SetVariable("pValue", 75);  ???????
            });
        </script>
    </head>
    <body>
        <div id="pct_gauge"></div>
    </body>
</html>
+1  A: 
$('#pctgauge')[0].SetVariable("pValue", 75);

Probably.

The key point is, jQuery objects (which are the most common things returned from calling $()) are arrays.

$("a") returns an array of all <a> elements. $('#pctgauge') returns an array of all elements having ID "pctgauge", which is a single-element array, but an array nevertheless. You must access its first element to call functions that are specifically defined on that element.

Tomalak
I had tried that:
Andrew Jones
With no luck. IE and FF both complaing that "'0' is null or not an object"
Andrew Jones
@Andrew: That's why I wrote "Probably". I'm not too confident since I've never worked with the jQuery swfobject plugin. Try @Loïc Février's answer instead, it looks better to me.
Tomalak
I did and I responded that it works in IE but not in FF or in Chrome. Thanks.
Andrew Jones
+1  A: 

According to http://jquery.thewikies.com/swfobject/examples I think you should do

$('#pctgauge').flash(
    function() {
        this.SetVariable("pValue", 75);
    }
);
Loïc Février
Thanks. That does work in IE but not in FireFox nor in Chrome.
Andrew Jones
I've never used it myself, but look at the page in my post, you should find all the info you need there.
Loïc Février