我在flash中制作了一个工作的AS3代码来显示和播放渐进式视频。我正在使用javascript动态地将其嵌入到具有指定宽度和高度的页面中。嵌入对象的高度和高度是正确的,但视频内容变得大于其容器的大小。那么当我将视频嵌入html中时,如何在AS3中调整视频大小以匹配它的容器对象?
AS3代码:
import flash.net.NetStream;
import flash.media.Video;
import flash.net.NetConnection;
import flash.events.MouseEvent;
var nc, ns, vd, st;
var isLoaded = false;
var isPlaying = false;
var vW = ExternalInterface.call('video.w');
var vH = ExternalInterface.call('video.h');
function video(w,h){
nc = new NetConnection(); nc.connect(null);
ns = new NetStream(nc);
vd = new Video(w,h);
ns.client = this;
vd.attachNetStream(ns);
stage.addChild(vd);
}
function playpause(e){
if(isLoaded == false){
ns.play('http://localhost.com/project/vid/sample_1.mp4');
isLoaded = true;
isPlaying = true;
}
else{
if(isPlaying == false){
ns.resume();
isPlaying = true;
}
else{
ns.pause();
isPlaying = false;
}
}
}
video(vW,vH);
stage.addEventListener(MouseEvent.CLICK, playpause);
HTML:
<!DOCTYPE html>
<html>
<head>
<title>video</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
function player(container,w,h){
var container = document.getElementById(container);
var flashHTML = '<object type="application/x-shockwave-flash" data="video.swf" width="'+w+'" height="'+h+'"><param name="movie" value="video.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#cccccc" /><param name="play" value="true" /><param name="loop" value="true" /><param name="wmode" value="window" /><param name="menu" value="true" /><param name="allowScriptAccess" value="sameDomain" /><a href="http://www.adobe.com/go/getflash"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></object>';
container.innerHTML = flashHTML;
this.w = function(){return w}
this.h = function(){return h}
}
</script>
</head>
<body>
<div id="flashContent"></div>
<script>
var video = new player('flashContent',853,480);
</script>
</body>
</html>
答案 0 :(得分:0)
您需要将video.w和video.h称为函数,以便返回值。
var vW = ExternalInterface.call('video.w()');
var vH = ExternalInterface.call('video.h()');
应该有效