开发者

How to SetVariable in jQuery

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>
    开发者_如何学JAVA    <div id="pct_gauge"></div>
    </body>
</html>


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

$('#pctgauge').flash(
    function() {
        this.SetVariable("pValue", 75);
    }
);


$('#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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜