javascript - flash: ExternalInterface works with embed tag but not with object tag - Stack Overflow

The "modern" updated way to embed a flash object, according to Adobe:<object id="theF

The "modern" updated way to embed a flash object, according to Adobe:

        <object id="theFlash" name="theFlash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" 
         width="400" height="225" align="middle">
            <param name="movie" value="theflashfile.swf" />
            <param name="allowScriptAccess" value="always" />
            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash"
             data="getStreamFrame.swf" width="400" height="225">
            <param name="allowScriptAccess" value="always" />
            <!--<![endif]-->
            <a href="">
                <img src=".gif" alt="Get Adobe Flash player" />
            </a>
            <!--[if !IE]>-->
            </object>
            <!--<![endif]-->
        </object>

When trying to call an AS3 function in the SWF, from Javascript:

     var flashObj = document.getElementById('theFlash');
     flashObj.someASFunction();

(and on the AS side:)

     import flash.external.*;
     function someASFunction() {
        //show some text
     }
     ExternalInterface.addCallback("someASFunction", someASFunction);

This doesn't work in Firefox and Chrome. The flash works and loads. flashObj does get a reference to the object, but someASFunction is undefined and doesn't get called.

If I replace the object tag with an embed tag:

   <embed id="theFlash" name="theFlash" height="225" width="400" align="middle" 
    type="application/x-shockwave-flash" allowscriptaccess="always"
    src="theflashfile.swf" />

Then it works on Firefox and Chrome (the AS function is called and works properly) - (it doesn't work in IE though).

How e it doesn't work with an object tag?
How "safe" it is to use the embed tag instead of the object tag? Is it not obsolete?

Note, that it is definitely not a timing issue - If I call the AS function from JS from an onclick function - then the results are the same.

The "modern" updated way to embed a flash object, according to Adobe:

        <object id="theFlash" name="theFlash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" 
         width="400" height="225" align="middle">
            <param name="movie" value="theflashfile.swf" />
            <param name="allowScriptAccess" value="always" />
            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash"
             data="getStreamFrame.swf" width="400" height="225">
            <param name="allowScriptAccess" value="always" />
            <!--<![endif]-->
            <a href="http://www.adobe./go/getflash">
                <img src="http://www.adobe./images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
            </a>
            <!--[if !IE]>-->
            </object>
            <!--<![endif]-->
        </object>

When trying to call an AS3 function in the SWF, from Javascript:

     var flashObj = document.getElementById('theFlash');
     flashObj.someASFunction();

(and on the AS side:)

     import flash.external.*;
     function someASFunction() {
        //show some text
     }
     ExternalInterface.addCallback("someASFunction", someASFunction);

This doesn't work in Firefox and Chrome. The flash works and loads. flashObj does get a reference to the object, but someASFunction is undefined and doesn't get called.

If I replace the object tag with an embed tag:

   <embed id="theFlash" name="theFlash" height="225" width="400" align="middle" 
    type="application/x-shockwave-flash" allowscriptaccess="always"
    src="theflashfile.swf" />

Then it works on Firefox and Chrome (the AS function is called and works properly) - (it doesn't work in IE though).

How e it doesn't work with an object tag?
How "safe" it is to use the embed tag instead of the object tag? Is it not obsolete?

Note, that it is definitely not a timing issue - If I call the AS function from JS from an onclick function - then the results are the same.

Share Improve this question asked Sep 19, 2011 at 16:45 Yuval A.Yuval A. 6,11912 gold badges55 silver badges65 bronze badges 4
  • 1 don't bother with static embedding, use swfobject! – grapefrukt Commented Sep 19, 2011 at 17:02
  • The embed tag is included in the HTML5 spec. html5doctor./element-index/#e – Lars Blåsjö Commented Sep 19, 2011 at 20:39
  • I'm running into the same issue. When using swfobject 2.2, Chrome gets the object tag, and then my AS function does not work. If I use swfobject 1.5, Chrome gets the embed tag, and my AS function works. I would like to use the latest swfobject, but I also need my AS function to work. Any updates here? – Nick B Commented Apr 13, 2012 at 18:19
  • Someone found a solution? I'm using SwfObject 2.2 like Nick and IE doesn't execute calls to flash :( – DanielB Commented Jun 8, 2012 at 16:43
Add a ment  | 

3 Answers 3

Reset to default 4

When using the remended Adobe method, I also failed to target the flashmovie in FF and Chrome. I ended up using the following code and ExternalInterface works just fine in all browsers

    <div id="flashContent">

        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="619" height="99" id="myFlashMovie" align="middle">
            <param name="movie" value="myFlashMovie.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#f2f2f2" />
            <param name="allowScriptAccess" value="sameDomain" />
            <!--[if !IE]>-->
            <embed src="myFlashMovie.swf" quality="high" bgcolor="#f2f2f2"
             width="619" height="99" name="myFlashMovie" align="middle"
             play="true" loop="true" quality="high" allowScriptAccess="sameDomain"
             type="application/x-shockwave-flash"
             pluginspage="http://www.macromedia./go/getflashplayer">
        </embed>
            <!--<![endif]-->
        </object>

For targeting the flash movie, I use this java script

        function sendDataToFlash(data) {

            getFlashMovie("myFlashMovie").myCallbackInFlash(data);

        }

        function getFlashMovie(movieName) {
            var isIE = navigator.appName.indexOf("Microsoft") != -1;
            if(isIE) return window[movieName];
            else return document[movieName];

        }

for static embedding (which i like more) i use this code (this one is for my invisible mp3 player):

<object style="position:fixed" id="1pixPlayer" width="1" height="1" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">
    <param value="transparent" name="wmode">
    <param value="1pxMp3.swf" name="movie">
    <param value="always" name="allowScriptAccess">
<embed name="1pixPlayer" width="1" height="1" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" src="1pxMp3.swf"></object>

For me it starts working if I assign a distinct id to the nested object tag and make calls to exactly this object.

        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100%" height="100%" id="launcher"
                align="middle">
            <param name="movie" value="/flex-frontend/launcher.swf?version=1.3"/>
            <param name="flashvars"
                   value="sessionId=${session.id}"/>
            <param name="wmode" value="direct"/>
            <param name="allowFullScreen" value="true"/>
            <param name="bgcolor" value="#000000"/>
            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash" id="launcher1" data="/flex-frontend/launcher.swf?version=1.3"
                    width="100%" height="100%">
                <param name="flashvars"
                       value="sessionId=${session.id}"/>
                <param name="wmode" value="direct"/>
                <param name="allowFullScreen" value="true"/>
                <param name="bgcolor" value="#000000"/>
                <!--<![endif]-->
                <a href="http://www.adobe./go/getflash">
                    Flash player version not less than 10.3 is required!
                </a>
                <!--[if !IE]>-->
            </object>
            <!--<![endif]-->
        </object>

Then from javascript:

// This doesn't work
// var flashObj = $("#launcher");
// But this does
var flashObj = $("#launcher1");
var screenshotData = flashObj.get(0).exportScreenshot();

Work for both Chrome and FF.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744368855a4570846.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信