SWFOBJECT CurrentFrame Javascript

发布于 2024-11-17 02:16:58 字数 1862 浏览 7 评论 0原文

我在播放当前帧时遇到了挑战。我正在使用 swfobject 版本 2.2。

这是我的脚本:

 <script type="text/javascript">

        function flashplayer(flashname) {

            var flashvars = {};
            var params = {};
            params.play = "true";
            params.menu = "true";
            params.scale = "noscale";
            params.allowfullscreen = "true";
            var attributes = {
                id: "flashDiv",
                name: "flashDiv"
            };
            swfobject.embedSWF(flashname, "myAlternativeContent", "800", "600", "9.0.0", flashvars, params, attributes);
            var obj = swfobject.getObjectById("myAlternativeContent");
            totalFrames = obj.totalFrames;
            $('#duration').html(totalFrames);
            currentFrame1 = obj.currentFrame;
            $('#current').html(currentFrame1);
            obj.addEventListener("onStateChange", "onytplayerStateChange");
        }
        function onStateChange() {
            var obj = swfobject.getObjectById("myAlternativeContent");
            currentFrame1 = obj.TcurrentFrame;
            $('#current').html(currentFrame1);
        }
        function stopflash() {
            var obj = swfobject.getObjectById("myAlternativeContent");
            obj.Stop();
        }
        function PlayFlash() {
            var obj = swfobject.getObjectById("myAlternativeContent");
            obj.Play();
        }
        function FlashRewind() {
            var obj = swfobject.getObjectById("myAlternativeContent");
            obj.Rewind();
        }
    </script>

   <div id="duration">
        1
    </div>
    <div id="current">
        1
    </div>
    <input onclick="flashplayer('../../Video/test.swf');" type="button" style="width: 300px"
        value="play flash" /><br />

提前致谢。

I am having a challenge getting the current frame playing. I am using swfobject ver 2.2.

Here is my script:

 <script type="text/javascript">

        function flashplayer(flashname) {

            var flashvars = {};
            var params = {};
            params.play = "true";
            params.menu = "true";
            params.scale = "noscale";
            params.allowfullscreen = "true";
            var attributes = {
                id: "flashDiv",
                name: "flashDiv"
            };
            swfobject.embedSWF(flashname, "myAlternativeContent", "800", "600", "9.0.0", flashvars, params, attributes);
            var obj = swfobject.getObjectById("myAlternativeContent");
            totalFrames = obj.totalFrames;
            $('#duration').html(totalFrames);
            currentFrame1 = obj.currentFrame;
            $('#current').html(currentFrame1);
            obj.addEventListener("onStateChange", "onytplayerStateChange");
        }
        function onStateChange() {
            var obj = swfobject.getObjectById("myAlternativeContent");
            currentFrame1 = obj.TcurrentFrame;
            $('#current').html(currentFrame1);
        }
        function stopflash() {
            var obj = swfobject.getObjectById("myAlternativeContent");
            obj.Stop();
        }
        function PlayFlash() {
            var obj = swfobject.getObjectById("myAlternativeContent");
            obj.Play();
        }
        function FlashRewind() {
            var obj = swfobject.getObjectById("myAlternativeContent");
            obj.Rewind();
        }
    </script>

   <div id="duration">
        1
    </div>
    <div id="current">
        1
    </div>
    <input onclick="flashplayer('../../Video/test.swf');" type="button" style="width: 300px"
        value="play flash" /><br />

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

っ左 2024-11-24 02:16:58

快速浏览一下,我发现您的代码存在三个问题。

  1. 通过在属性对象中指定 ID 和名称,您可以为新创建的 分配一个名称。这意味着 swfobject.getObjectById("myAlternativeContent") 将不起作用,因为您已将 重命名为“flashDiv”。您应该改用 swfobject.getObjectById("flashDiv")

  2. 您尝试在 swfobject.embedSWF 之后立即使用 swfobject.getObjectById。但是,这可能不起作用,因为在调用 swfobject.getObjectById 之前嵌入可能无法完成。 (顺便说一句,仅静态发布需要 getObjectById;使用动态发布时,使用标准 getElementById 就可以了)

  3. 您没有指定快速安装参数,因此您的 SWFObject 语法无效。请改用此选项:

.

swfobject.embedSWF(flashname, "myAlternativeContent", "800", "600", "9.0.0", false, flashvars, params, attributes);

#1 和 #2 的解决方案是使用 SWFObject 的callback 功能。这有助于确保在嵌入成功之前不会调用 DOM 函数,从而有助于计时。它还提供对嵌入 的引用,使您能够避免进行 swfobject.getObjectById 调用。

function flashplayer(flashname) {

    var flashvars = {};
    var params = {};
    params.play = "true";
    params.menu = "true";
    params.scale = "noscale";
    params.allowfullscreen = "true";
    var attributes = {
        id: "flashDiv",
        name: "flashDiv"
    };
    function mycallback(event){
        var obj = event.ref;
        totalFrames = obj.totalFrames;
        $('#duration').html(totalFrames);
        currentFrame1 = obj.currentFrame;
        $('#current').html(currentFrame1);
        obj.addEventListener("onStateChange", "onytplayerStateChange");
    }
    swfobject.embedSWF(flashname, "myAlternativeContent", "800", "600", "9.0.0", false, flashvars, params, attributes, mycallback);
}

请记住,您可能仍然会遇到时间问题; 嵌入页面后,就会调用 SWFObject 的回调 - 这并不意味着 SWF 已完成加载。

您可以通过结合 JavaScript setInterval 检查 Flash Player 的 PercentLoaded 方法来检查 SWF 的加载状态。

var obj = event.ref;
if(obj.PercentLoaded() === 100){
    //do stuff
} else {
    //Use setInterval to check PercentLoaded again
}

At a quick glance, I see three problems with your code.

  1. By specifying an ID and name in your attributes object, you're assinging a name to the newly created <object>. This means swfobject.getObjectById("myAlternativeContent") won't work, because you've renamed the <object> to "flashDiv". You should use swfobject.getObjectById("flashDiv") instead.

  2. You're trying to use swfobject.getObjectById immediately after swfobject.embedSWF. However this probably won't work, because the embed might not be completed before swfobject.getObjectById is invoked. (BTW, getObjectById is only needed for static publishing; when using dynamic publishing, it's ok to use the standard getElementById)

  3. You're not specifying the express install parameter, so your SWFObject syntax is invalid. Use this instead:

.

swfobject.embedSWF(flashname, "myAlternativeContent", "800", "600", "9.0.0", false, flashvars, params, attributes);

.

A solution to #1 and #2 is to use SWFObject's callback feature. This helps with timing by ensuring you won't invoke your DOM functions until the embed is successful. It also provides a reference to the embedded <object> which enables you to avoid making the swfobject.getObjectById call.

function flashplayer(flashname) {

    var flashvars = {};
    var params = {};
    params.play = "true";
    params.menu = "true";
    params.scale = "noscale";
    params.allowfullscreen = "true";
    var attributes = {
        id: "flashDiv",
        name: "flashDiv"
    };
    function mycallback(event){
        var obj = event.ref;
        totalFrames = obj.totalFrames;
        $('#duration').html(totalFrames);
        currentFrame1 = obj.currentFrame;
        $('#current').html(currentFrame1);
        obj.addEventListener("onStateChange", "onytplayerStateChange");
    }
    swfobject.embedSWF(flashname, "myAlternativeContent", "800", "600", "9.0.0", false, flashvars, params, attributes, mycallback);
}

Bear in mind you may still encounter timing issues; SWFObject's callback is invoked as soon as the <object> is embedded in the page -- it doesn't mean the SWF has finished loading.

You can check the SWF's loading status by checking Flash Player's PercentLoaded method combined with a JavaScript setInterval.

var obj = event.ref;
if(obj.PercentLoaded() === 100){
    //do stuff
} else {
    //Use setInterval to check PercentLoaded again
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文