scigoat
06-29-2007, 08:23 PM
I got the following code from the macromedia site to load videos into my swf file using javascript and the External Interface class.
Here is the code I am using:
Action Script:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("playVideo", null, playVideo);
ExternalInterface.addCallback("pauseResume", null, pauseResume);
var server_nc:NetConnection = new NetConnection();
server_nc.connect(null);
var video_ns:NetStream = new NetStream(server_nc);
selected_video.attachVideo(video_ns);
video_ns.onStatus = function(obj:Object):Void {
ExternalInterface.call("updateStatus", " " + obj.code);
};
function playVideo(url:String):Void {
video_ns.play(url);
}
function pauseResume():Void {
video_ns.pause();
}
And here is the javascript in my HTML document:
<script language="JavaScript">
var flashVideoPlayer;
function initialize() {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
flashVideoPlayer = (isIE) ? window['videoPlayer'] : document['videoPlayer'];
}
function callFlashPlayVideo() {
var comboBox = document.forms['videoForm'].videos;
var video = comboBox.options[comboBox.selectedIndex].value;
updateStatus("____" + video + "____");
flashVideoPlayer.playVideo(video);
}
function callFlashPlayPauseVideo() {
flashVideoPlayer.pauseResume();
}
function updateStatus(message) {
document.forms['videoForm'].videoStatus.value += message + "\n";
}
function loadVideo(video) {
updateStatus("____" + video + "____");
flashVideoPlayer.playVideo(video);
}
</script>
</head>
<body bgcolor="#ffffff" onLoad="initialize();">
<div id="container">
<div id="content_container">
<div id="content">
<div style="padding: 20px 0 0 0;"> </div>
<center>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="331" height="292" id="videoPlayer" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="movie" value="video.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="video.swf" quality="high" bgcolor="#ffffff" width="331" height="292" name="videoPlayer" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<form name="videoForm">
Select a video:<br />
<select name="videos">
<option value="cafe_townsend_chef.flv">cafe_townsend_chef.flv</option>
</select>
<input type="button" name="selectVideo" value="play" onClick="callFlashPlayVideo();" />
<br /><br />
Playback <input type="button" name="playPause" value="play/pause" onClick="callFlashPlayPauseVideo();" />
<br /><br />
Video status messages <br />
<textarea name="videoStatus" cols="50" rows="10"></textarea>
</form>
<p>
<a href="javascript:void(0)" onClick="loadVideo('got_shot_VP6_512K.flv');">Got Shot</a><br />
<a href="javascript:void(0)" onClick="loadVideo('fantasy_arab.flv');">Fantasy Arabs</a><br />
<a href="javascript:void(0)" onClick="loadVideo('cafe_townsend_chef.flv');">Chef Video</a><br />
</p>
</center>
</div><!-- #content -->
</div><!-- #content_container -->
</div><!-- #containter -->
</body>
</html>
Everything is working fine. Including the 3 <a href="javascript:void(0)" onClick="loadVideo('');"></a> at the bottom of the html code. However, what I want to do is get rid of the form, and simply use the <a href="javascript:void(0)" onClick="loadVideo('');"></a> to load the videos. I realize I can't just delete that form code, but I am not familiar with javascript, can someone please help?
Here is the code I am using:
Action Script:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("playVideo", null, playVideo);
ExternalInterface.addCallback("pauseResume", null, pauseResume);
var server_nc:NetConnection = new NetConnection();
server_nc.connect(null);
var video_ns:NetStream = new NetStream(server_nc);
selected_video.attachVideo(video_ns);
video_ns.onStatus = function(obj:Object):Void {
ExternalInterface.call("updateStatus", " " + obj.code);
};
function playVideo(url:String):Void {
video_ns.play(url);
}
function pauseResume():Void {
video_ns.pause();
}
And here is the javascript in my HTML document:
<script language="JavaScript">
var flashVideoPlayer;
function initialize() {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
flashVideoPlayer = (isIE) ? window['videoPlayer'] : document['videoPlayer'];
}
function callFlashPlayVideo() {
var comboBox = document.forms['videoForm'].videos;
var video = comboBox.options[comboBox.selectedIndex].value;
updateStatus("____" + video + "____");
flashVideoPlayer.playVideo(video);
}
function callFlashPlayPauseVideo() {
flashVideoPlayer.pauseResume();
}
function updateStatus(message) {
document.forms['videoForm'].videoStatus.value += message + "\n";
}
function loadVideo(video) {
updateStatus("____" + video + "____");
flashVideoPlayer.playVideo(video);
}
</script>
</head>
<body bgcolor="#ffffff" onLoad="initialize();">
<div id="container">
<div id="content_container">
<div id="content">
<div style="padding: 20px 0 0 0;"> </div>
<center>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="331" height="292" id="videoPlayer" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="movie" value="video.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="video.swf" quality="high" bgcolor="#ffffff" width="331" height="292" name="videoPlayer" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<form name="videoForm">
Select a video:<br />
<select name="videos">
<option value="cafe_townsend_chef.flv">cafe_townsend_chef.flv</option>
</select>
<input type="button" name="selectVideo" value="play" onClick="callFlashPlayVideo();" />
<br /><br />
Playback <input type="button" name="playPause" value="play/pause" onClick="callFlashPlayPauseVideo();" />
<br /><br />
Video status messages <br />
<textarea name="videoStatus" cols="50" rows="10"></textarea>
</form>
<p>
<a href="javascript:void(0)" onClick="loadVideo('got_shot_VP6_512K.flv');">Got Shot</a><br />
<a href="javascript:void(0)" onClick="loadVideo('fantasy_arab.flv');">Fantasy Arabs</a><br />
<a href="javascript:void(0)" onClick="loadVideo('cafe_townsend_chef.flv');">Chef Video</a><br />
</p>
</center>
</div><!-- #content -->
</div><!-- #content_container -->
</div><!-- #containter -->
</body>
</html>
Everything is working fine. Including the 3 <a href="javascript:void(0)" onClick="loadVideo('');"></a> at the bottom of the html code. However, what I want to do is get rid of the form, and simply use the <a href="javascript:void(0)" onClick="loadVideo('');"></a> to load the videos. I realize I can't just delete that form code, but I am not familiar with javascript, can someone please help?