I made a working AS3 code in flash to display and play a progressive video. I'm using javascript to dynamically embed it in a page with specified width and height. The embeded object's with and height is correct but the video content becomes larger than the size of its container. So how do I resize video in AS3 to match it's container object when it's embeded in html?
AS3 Code:
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>