0
我在Flash中制作了一个可用的AS3代码来显示和播放渐进式视频。我正在使用JavaScript动态地将其嵌入到指定宽度和高度的页面中。嵌入对象的with和height是正确的,但视频内容变得比它的容器大。那么如何在AS3中调整视频的大小以匹配其在HTML中嵌入的容器对象?调整Flash动作脚本中的视频对象3
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>
丹,这不是正确的答案,因为支架不要在此情况下,无所谓。 – Gio
我经过几个小时的追踪才找出答案。我有一个与视频相同的尺寸为'640 x 360'的舞台。如果我动态调整比舞台更大的视频,问题就会发生。在应用新的尺寸更改后,视频扩展为“853 x 480”,而舞台仍保留“640 x 360”作为原始视频。设置舞台的scalemode和重新定位解决了视频显示问题。 >> stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; –
@Gio只是好奇,我在Chrome中的控制台将返回该函数本身,如果我没有()后运行它。这是一个仅限铬的行为吗?迈克尔,很高兴你知道了。我之前在舞台比例设置中遇到过类似的问题,对不起,我没有早点想到。 – dprogramz