用于嵌入Flash (swf) 文件的开源JavaScript框架swfobject

我自己也没真正在项目中使用过swfobject这款开源javascript框架,看到有使用该框架做视频类项目的,于是大致看了一下,记录下来,以后用到的话能快速上手.

先介绍一下swfobject框架:

An open source Javascript framework for detecting the Adobe Flash Player plugin and embedding Flash (swf) files.

翻译过来就是,这是一款用于检测Adobe Flash Player插件和嵌入Flash(swf)文件的开源JavaScript框架.

官网地址:http://jquery.thewikies.com/swfobject/

至于使用,像javascript框架jquery框架使用方法都大同小异

引入需要的javascript文件,这个官网有,开始调用吧

<html>
  <head>
    
    
    <title>My JSP 'swf.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script src="http://jquery.thewikies.com/swfobject/jquery.swfobject.1-1-1.js"></script>

<script>

flashMovie = null;

$(document).ready(
	function () {
		flashMovie = $('#flashInteract .movie');

		flashMovie.flash(
			{
				swf: 'http://127.0.0.1/xxx/xxx/01.swf',//待加载swf文件
				width:800,//视频宽
				height:500,//高
				play: true,//初始加载自动播放
				flashvars: {
					message: 'I come from Flash.'
				},
			}
		);
	}
);

function play() {
	flashMovie.flash(
		function() {
			this.Play();
		}
	);
}

function pause() {
	flashMovie.flash(
		function() {
			this.StopPlay();
		}
	);
}

function firstFrame() {
	flashMovie.flash(
		function() {
			this.GotoFrame(0);
		}
	);
}

function lastFrame() {
	flashMovie.flash(
		function() {
			this.GotoFrame(9);
		}
	);
}

function prevFrame() {
	flashMovie.flash(
		function() {
			var currentFrame = this.TGetProperty('/', 4),
				previousFrame = parseInt(currentFrame) - 2;

			if (previousFrame < 0) {
				previousFrame = 9;
			}

			this.GotoFrame(previousFrame);
		}
	);
}

function nextFrame() {
	flashMovie.flash(
		function() {
			var currentFrame = this.TGetProperty('/', 4),
				nextFrame = parseInt(currentFrame);

			if (nextFrame >= 10) {
				nextFrame = 0;
			}

			this.GotoFrame(nextFrame);
		}
	);
}

function sendToFlash() {
	flashMovie.flash(
		function() {
			this.SetVariable('/:message', document.getElementById('data').value);
		}
	);
}

function getFromFlash() {
	flashMovie.flash(
		function() {
			document.getElementById('data').value = this.GetVariable('/:message');
		}
	);
}

</script>


  </head>
  
  <body>
<div id="flashInteract">
	<div class="movie"></div>

		<p style="font-family: arial;">
			<input type="button" οnclick="firstFrame();" value="回到开头" />
			<input type="button" οnclick="prevFrame();" value="快退" />
			<input type="button" οnclick="play();" value="播放" />
			<input type="button" οnclick="pause();" value="暂停" />
			<input type="button" οnclick="nextFrame();" value="快进" />
			<input type="button" οnclick="lastFrame();" value="回到结尾" />
		</p>

		<p>
			<input type="text" value="I come from javascript." size="20" οnfοcus="this.select();" id="data" /> 
			<input type="button" οnclick="sendToFlash();" value="Send to Flash" />
			<input type="button" οnclick="getFromFlash();" value="Get from Flash" />
		</p>

</div>
  </body>
</html>

01.swf时我们要加载的swf文件


效果图:



如有错误,欢迎指正

end

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值