继续在IE中获得“对象不支持此属性或方法”错误

时间:2012-03-25 23:35:22

标签: javascript actionscript-3

我正在尝试为一个项目构建一个简单的HTML到Flash通信器,它在Firefox中运行良好,但我继续在IE中获得“对象不支持此属性或方法”错误。

它说错误的线是 document.getElementById("flashTest").sendValFromHtml(form.connection.value, form.location.value, form.postcode.value);

有人可以对这种情况有所了解吗?

<script type="text/javascript">
    function submitFlashCheck() {
        var form = document.getElementById("formTest");
        var hasConnection = form.connection.value.length != 0; 
        var hasLocation = form.location.value.length != 0;

        document.getElementById("connection").className = hasConnection ? "" : "invalid";
        document.getElementById("location").className = hasLocation ? "" : "invalid";

        if(hasConnection && hasLocation){
            //apparently causing error:
            document.getElementById("flashTest").sendValFromHtml(form.connection.value, form.location.value, form.postcode.value);                              
        }
    }
</script>


<div class="test mb-20">
    <form id="formTest" name="formTest" method="post" action="">
        <fieldset class="form">
            <div class="connection">
                <label id="connection">Connection:*</label>
                <div class="textwrapper">
                    <select name="connection">
                        <option value="">Select connection</option>
                        <option value="">----------------------</option>
                        <option value="100">100</option>
                        <option value="200">200</option>
                        <option value="500">500</option>
                    </select>
                </div>
            </div>
            <div class="location">
                <label id="location">Location*:</label>
                <div class="textwrapper">
                    <select name="location">
                        <option value="">Select your location</option>
                        <option value="">----------------------</option>
                        <option value="syd">Sydney</option>
                        <option value="melb">Melbourne</option>
                        <option value="can">Canberra</option>
                        <option value="bris">Brisban</option>
                    </select>
                </div>
            </div>
            <div class="postcode">
                <label>Postcode:</label>
                <div class="textwrapper">
                    <input type="text" name="postcode" id="postcode">
                </div>
            </div>
            <div class="start clear">
                <input class="button" type="button" name="sendToFlash" id="sendToFlash" value="Start Test" onclick="submitFlashCheck();" />
            </div>
        </fieldset>
    </form>

Flash:

<embed src="/flash/proj-3.swf" id="flashTest" name="flashTest" width="540" height="320" allowscriptaccess="always" type="application/x-shockwave-flash"  flashvars="jsfunc=pushResults&jsfunc2=showExtras" />

1 个答案:

答案 0 :(得分:1)

我感觉IE不喜欢<embed>元素(仍在搜索引用)。试试这个标记(取自SWFObject documentation

<object id="flashTest"
        classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
        width="540"
        height="320"
        allowscriptaccess="always"
        flashvars="jsfunc=pushResults&jsfunc2=showExtras">
    <param name="movie" value="/flash/proj-3.swf" />
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash"
            data="/flash/proj-3.swf"
            width="540"
            height="320"
            allowscriptaccess="always"
            flashvars="jsfunc=pushResults&jsfunc2=showExtras">
    <!--<![endif]-->
        <p>Alternative content</p>
    <!--[if !IE]>-->
    </object>
    <!--<![endif]-->
</object>