I spent the morning looking for a way to make a simple video player in as3 for a video mpu.. all it needed was a play pause button and a mute button, after searching the web I came up with this little code, put together from a few different sources.
Hope it helps some of you out there.. ( I haven't classed it up, didn't see the need for such a small little project)
import fl.video.*;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
// Set up the video component from the components lib name it display
//and add the source
var flvControl = display
var flvSource = "hhw_Intl_trailer_n_300k2.flv";
//Set up the sound transformer object used to control the volume.
var st:SoundTransform=new SoundTransform();
// Loop the video at end
function completeHandler(event:VideoEvent):void {
flvControl.seek(0);
flvControl.play();
playPause_btn.gotoAndPlay("play");
}
//
flvControl.addEventListener(VideoEvent.COMPLETE, completeHandler);
flvControl.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, playvideo);
function playvideo(event:VideoEvent):void{
//Opening Volume Set to Mute and Play Pause Btn set on pause
playPause_btn.gotoAndPlay(1);
// Not volume is now 0 - 1 not 0 - 100 so 50% audio would be 0.5
st.volume = 0;
flvControl.soundTransform = st;
//
mute_btn.gotoAndPlay("mute");
}
// Set the video path
flvControl.source = flvSource;
//Set Hand Vars - Puts the hand cursor back
playPause_btn.buttonMode = true;
mute_btn.buttonMode = true;
click_tag_mc.buttonMode = true;
// Add Play Pause Button code
function playHandler(event:MouseEvent):void {
if ( flvControl.playing ) {
flvControl.pause();
playPause_btn.gotoAndPlay("pause");
} else {
flvControl.play();
playPause_btn.gotoAndPlay("play");
}
}
playPause_btn.addEventListener(MouseEvent.CLICK, playHandler);
// add audio mute code
function audioHandler(event:MouseEvent):void {
if (flvControl.soundTransform.volume == 1) {
st.volume = 0;
flvControl.soundTransform = st;
mute_btn.gotoAndPlay("mute");} else {
st.volume = 1;
flvControl.soundTransform = st;
mute_btn.gotoAndPlay("unmute"); }
}
mute_btn.addEventListener(MouseEvent.CLICK, audioHandler);
//Click Tag
click_tag_mc.addEventListener(MouseEvent.CLICK,clickTag);
//Click Tag function
function clickTag(event:MouseEvent){
if(root.loaderInfo.parameters.clickTAG.substr(0,5) =="http:"){
navigateToURL(new URLRequest(root.loaderInfo.parameters.clickTAG),"_blank");
}
}
playPause_btn.gotoAndPlay(2);
Not to fancy but does the Job, some things worth noting.. the flash compliler seems to have some errors when it comes to adding the click tag var.. so you have to add it as a blank or "", well that's the only way i've found so far
If anyone would like the fla please let me know.
Update.
I've since discovered the right way to get the clickTAG into your as3 flash movie thanks to this general discussion at www.adobe.com click here to read it, i'm far to lazy to cut and paste. The Script is now updated for click Tag adserving.
technorati tags:as3, ads, mpu, actionscript, flv, as, flash cs3












August 17th, 2008 at 5:42 pm
I like very much the writings and pictures and explanations in your adress so I look forward to see your next writings. I congratulate you.