Create a skippable and redirectable video intro for a website

In 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.

View DemoDownload Source

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");
}

12 thoughts on “Create a skippable and redirectable video intro for a website

  1. Alain Tranquille

    One aspect of the above code that I don’t understand is the use of the use of the Video.flv.

    Is that a new external flash file which is being called into the the new flash file video.fla, because if my memory serves me well, the compiled version of a flash file has a .swf extension.

    Your prompt response would be appreciated, thank you.

    Alain.

  2. Daniel C.

    Thanks !!! This helpful information has allowed the new website for 2012 to look more awesome than ever!!!

    -Daniel C.
    General Manager
    Bayou Mobile Sound

  3. giannis

    Hello,

    I’m using the above code with an flv video that contains sound. The video appears correctly but without sound..
    How could i fix this issue?

    Thank you in advance!

  4. Sotos

    I can’t get the stop video redirect to work…
    Skip button works, but when the video ends it doesn’t redirect…
    Any help?

  5. LW

    Is there a way to buffer the video as mine is automatically ‘skipping’ before it has time to load more than 10 seconds?

  6. Theo

    Everything is very open with a very clear description of the issues.
    It was really informative. Your website is very helpful.
    Thank you for sharing!

  7. envios de dinero online

    Hi there! I hope you don’t mind but I decided to publish your web site: http://www.riacodes.com/flash/create-a-skippable-and-redirectable-video-intro-for-a-website/ to my internet directory website. I used, “Create a skippable and redirectable video intro for a website | RiaCodes” as your web site headline. I hope this is okay with you. However, if you’d like me to
    change the title or perhaps remove it entirely, email me at elishamcarthur@freenet.
    de. Appreciate it.

Leave a Reply

Your email address will not be published. Required fields are marked *