绵阳做网站_绵阳网站建设公司_绵阳网页制作_绵阳网页设计_绵阳网站制作设计公司

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 11974|回复: 1

swfobject.js 2简单使用方法

[复制链接]
发表于 2013-4-6 09:02:24 | 显示全部楼层 |阅读模式


<td>
<div id="container"><embed type="application/x-shockwave-flash" src="player.swf" width="302" height="208" style="undefined" id="ply" name="ply" bgcolor="#FFFFFF" quality="high" allowfullscreen="true" allowscriptaccess="always" flashvars="file=video.flv&image=preview.jpg"></div>
                            <script type="text/javascript" src="swfobject.js"></script>                            <script type="text/javascript">                                var s1 = new SWFObject("player.swf", "ply", "302", "208", "9", "#FFFFFF");                                s1.addParam("allowfullscreen", "true");                                s1.addParam("allowscriptaccess", "always");                                s1.addParam("flashvars", "file=video.flv&image=preview.jpg");                                s1.write("container");
      </script>

</td>
官方网址介绍
http://code.google.com/p/swfobject/wiki/documentation

用法:
html部分
<div id="swf1">......</div>
js部分   
swfobject.embedSWF("test.swf", "swf1", "300", "120", "9.0.0",);

源码部分:
这是2.2中的源码。看参数就明白怎么使用了。
embedSWF: function(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn) {

....}

详解
首先需要了解object标签。
http://www.w3school.com.cn/tags/tag_object.asp
http://www.w3school.com.cn/tags/tag_param.asp

swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr
这些依次为,swf位置,html要替换成flash的元素的id,宽,高,flash版本,如果没有flash那就使用这个自动安装flash的文件 swfobject2.2源文件里有


flashvarsObj:这里是flashvars的值。这个常用来作为html与flash之间传递参数,本来是在params对象中的属性,由于考虑到常用和方便,所以单独取了出来。可以设置为null。然后在param中写。

param对象的属性:
详细的介绍http://kb2.adobe.com/cps/127/tn_12701.html
play,loop,menu,quality,scale,salign,bgcolor,base,swliveconnect,flahvars,devicefont ,allowscriptaccess ,seamlesstabbing ,allowfullscreen ,allownetworking
wmode     这个很重要,window,opaque,transparent(一般设为transparent透明或者opaque不透明)。当不设置时默认为window,这时已窗口方式呈现。这时object元素将始终显示在最上面,同时点击事件等也监听不到。

attributes对象的属性:id,name,styleclass(不使用class,因为class也是ECMA4的保留关键字),align

callbackFn:回调函数





使用演示
演示1

swfobject.embedSWF("test6_flashvars.swf", "content5", "300", "120", "6.0.0", "expressInstall.swf", {name1:"hello",name2:"world",name3:"foobar"}, {menu:"false"}, {id:"dynamicContent5",name:"dynamicContent5"});
演示2

var flashvars = {
  name1: "hello",
  name2: "world",
  name3: "foobar"
};
var params = {
  menu: "false"
};
var attributes = {
  id: "dynamicContent2",
  name: "dynamicContent2"
};
swfobject.embedSWF("test6_flashvars.swf", "content2", "300", "120", "6.0.0", "expressInstall.swf", flashvars, params, attributes);
演示3

var flashvars = {};  <br>flashvars.xmlPath = "data.xml";  <br>var params = {};  <br>params.wmode = "transparent";  <br>var attributes = {};  <br>swfobject.embedSWF("xixi.swf","banner","960","250","9.0.0","expressInstall.swf",flashvars,params,attributes);<br>
演示4

swfobject.embedSWF("gen_shu.swf", "gen_swf1", "180", "105", "9.0.0",null,null,{wmode:"transparent"},null,function(){alert("已加载成功flash")});
js调用方法

http://code.google.com/p/swfobject/wiki/api
kmaygy.com

绵阳网站建设 | 绵阳做网站 —— 剑锋所指 所向披靡!
 楼主| 发表于 2013-4-6 09:24:24 | 显示全部楼层
<!--酷播迷你 CuPlayerMiniV2.0 代码开始-->
<script type="text/javascript" src="swfobject.js"></script>
<div id="CuPlayer">
<strong>酷播迷你(CuPlayerMiniV2.0) 提示:您的Flash Player版本过低,请<a href="http://www.CuPlayer.com/" >点此进行播放器升级</a>!</strong>
</div>
<script type="text/javascript">
var so = new SWFObject("CuPlayerMiniV20_Gray_S.swf","CuPlayer","260","230","9","#1b6cc5");
so.addParam("allowfullscreen","true");
so.addParam("allowscriptaccess","always");
so.addParam("wmode","opaque");
so.addParam("quality","high");
so.addParam("salign","lt");
so.addVariable("CuPlayerFile","sp.flv");
so.addVariable("CuPlayerImage","Images/qm1.jpg");
so.addVariable("CuPlayerShowImage","true");
so.addVariable("CuPlayerWidth","260");
so.addVariable("CuPlayerHeight","230");
so.addVariable("CuPlayerAutoPlay","true");
so.addVariable("CuPlayerAutoRepeat","true");
so.addVariable("CuPlayerShowControl","true");
so.addVariable("CuPlayerAutoHideControl","false");
so.addVariable("CuPlayerAutoHideTime","6");
so.addVariable("CuPlayerVolume","80");
so.write("CuPlayer");       
</script>
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|手机版|Archiver|绵阳网站建设

GMT+8, 2024-11-5 21:43 , Processed in 0.043733 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表