开发者

swfobject.embedSWF doesn't do anything. What am i missing?

I am experimenting with with swfObject to embed a flash video player on my site. here is some snippets of my code:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>

<script type="text/javascript">

if (typeof ARI == 'undefined')
{
     ARI = {};
}

ARI.InsertFlash = function()
{
    var flashvars =开发者_如何学编程 {};
    var parameters = {};
    parameters.quality = 'high';
    parameters.play = 'true';
    parameters.LOOP = 'false';
    parameters.wmode = 'transparent';
    parameters.allowScriptAccess='true';

    var attributes = {};

    attributes.id='ARIVID';

    swfobject.embedSWF("AS3MediaPlayer.swf","inlieu","720","405","9.0.0","",flashvars,parameters);
    }
</script>

...

<body>
<div class='inlieu'>
       <p> this will be replaced</p>
</div>
<button type='button' onclick='ARI.insertFlash();'>Insert</button>

This does nothing. my button does hit the correct function (please excuse any html errors that might be on the page). I've tested that with a div. The function itself does fire, but my div doesn't get replaced. What am I missing here? I want to embed a flash object that uses external interface, so any answers to my question that keeps that in context would be helpful. Also i want this to fire when a user pushes the button, not on page load, like most of the examples on the internet show.

thanks

Ari


SWFObject requires an ID on the target element, You're using a class. Change class='inlieu' to id='inlieu'

Also, since you're specifying an ID in the attributes, your new object will have the ID ARIVID and will NOT inherit the ID inlieu

This

<body>
<div id='inlieu'>
   <p> this will be replaced</p>
</div>
<button type='button' onclick='ARI.insertFlash();'>Insert</button>

will become this

<body>
<object id="ARIVID" ... ></object>
<button type='button' onclick='ARI.insertFlash();'>Insert</button>


um you are loading swfobject from http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js
Put the file in the same domain as your swf/html and your issue should go away.
Aside from trying to steal bandwidth you have no reason to loading from google and this can cause you version issues, if they decide to update that code base with something new.

Also you should be calling that function onLoad or from a button click as you stated. The code you posted is running before the page is finished loading and that javascript file from google may not be loaded yet.
You can test this by putting this code right before the embed statement.

alert( swfobject );
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜