ActionScript
These first lines of ActionScript set the variables. The first couple of lines state that the video starts paused and the sound is on.
var isVideoPlaying:Boolean = false;
var isVideoSoundOn:Boolean = true;
var videoFileName:String = “Imports/PortfolioSize_1.flv”;
var videoPlayer:MovieClip = videoHolder;
var videoPlay:MovieClip = play_btn;
var videoPause:MovieClip = pause_btn;
My site requires videos with Alpha preserved, as I need them to appear as if on walls. The best filetype for doing this is FLV, and the only way to get FLVs into Flash is with the NetStream command. The following code is how to get the FLVs into a MovieClip.
var videoNetConnection:NetConnection = new NetConnection();
videoNetConnection.connect(null);
videoNetStream = new NetStream(videoNetConnection);
videoPlayer.attachVideo(videoNetStream);
videoNetStream.play(videoFileName);
videoNetStream.pause();
videoNetStream.onMetaData = function(obj)
{
videoPlayer._height = obj.height;
videoPlayer._width = obj.width;
videoLength = obj.duration;
};
videoLoadCheck = setInterval(checkBytesLoaded, 1, videoNetStream);
The following code sets the buttons for playing and stopping the video. They are both the same size and position as the video, effectively making the frame for the video its own play/pause button.
function pauseVideo() {
videoNetStream.pause();
isVideoPlaying = false;
videoStatus();
clearInterval(adjustVideoProgress);
}
function playVideo(){
videoNetStream.pause();
isVideoPlaying = true;
videoStatus();
clearInterval(adjustVideoProgress);
}
videoPlay.onRelease = function(){
playVideo();
}
videoPause.onRelease = function (){
pauseVideo();
}
As the two buttons are in the same place, I need to hide the play button whilst the video is playing and hide the pause button whilst the video is paused. The same happens with the volume.
function videoStatus(){
if (isVideoPlaying == true){
_parent.isTrailerPlaying = true;
videoPause._visible = true;
videoPlay._visible = false;
}else if (isVideoPlaying == false){
_parent.isTrailerPlaying = false;
videoPause._visible = false;
videoPlay._visible = true;
}
}
function volumeControl(){
if (isVideoSoundOn == true){
videoMute._visible = true;
videoUnMute._visible = false;
videoSound.setVolume(100)
}else if (isVideoSoundOn== false){
videoMute._visible = false;
videoUnMute._visible = true;
videoSound.setVolume(0);
}
}
The final part of code restarts the video when it is finished.
function restartVideo(){
videoNetStream.seek(0);
clearInterval(adjustVideoProgress);
var adjustVideoProgress = setInterval(videoProgress,10)
}