Create a skippable and redirectable video intro for a website
February 24th, 2010 in Flash | 3 CommentsIn the following actionscript 3 lesson, we are going to create a video intro that the user can skip to access the main site or that will automatically redirect to the main site when the video has finished playing.
1. Create a new flash file (Actionscript 3.0) and save it as video.fla.
2. Rename “layer1″ to “btn”. Create the “skip” button and give it an instance of skip_btn.
3. Create an “actions” layer and open the actions panel.
First, we need to set up the video and add to the NetStream instance a listener for the NET_STATUS event.
var conn:NetConnection = new NetConnection(); conn.connect(null); var stream:NetStream = new NetStream(conn); stream.addEventListener(NetStatusEvent.NET_STATUS, onStatus); stream.client = this; var video:Video = new Video(); video.width = 640; video.height = 480; video.x = 0; video.y = 0; addChild(video); video.attachNetStream(stream);
4. The onStatus function detects the end of the video stream in order to redirect the user to the main page of the site.
function onStatus(e:Object):void{
if(e.info.code == "NetStream.Play.Stop") gotoSite();
}
Then play the video :
stream.play("video.flv");
5. Finally we create the gotoSite function that will be called either by the skip button or when the videos has finished playing.
skip_btn.addEventListener(MouseEvent.CLICK, gotoSite);
function gotoSite(e:Event = null):void{
navigateToURL(new URLRequest("http://www.riacodes.com"), "_self");
}
6. Here’s the entire code, test your movie to see the code in action.
var conn:NetConnection = new NetConnection();
conn.connect(null);
var stream:NetStream = new NetStream(conn);
stream.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
stream.client = this;
var video:Video = new Video();
video.width = 640;
video.height = 480;
video.x = 0;
video.y = 0;
addChild(video);
video.attachNetStream(stream);
function onStatus(e:Object):void{
if(e.info.code == "NetStream.Play.Stop") gotoSite();
}
stream.play("video.flv");
skip_btn.addEventListener(MouseEvent.CLICK, gotoSite);
function gotoSite(e:Event = null):void{
navigateToURL(new URLRequest("http://www.riacodes.com"), "_self");
}






Mar 3rd, 2010
Very nice ! Thanks
Mar 7th, 2010
Thanks I was just looking for this!
Mar 31st, 2010
Great Post, using it now