Create a skippable and redirectable video intro for a website

February 24th, 2010 in Flash | 7 Comments

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");
}
  • Digg
  • del.icio.us
  • Reddit
  • StumbleUpon
  • Twitter


What you think ...

(7 Comments)

+ Add a Comment
  1. Hank
    Mar 3rd, 2010

    Very nice ! Thanks

  2. Jo
    Mar 7th, 2010

    Thanks I was just looking for this!

  3. Paco
    Mar 31st, 2010

    Great Post, using it now

  4. Oscar
    Oct 11th, 2010

    can and intro video be created with out the used of flash?

  5. Alain Tranquille
    Nov 15th, 2010

    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.

  6. aans
    Jan 1st, 2011

    thanks. its very nice

  7. Daniel C.
    Dec 5th, 2011

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

    -Daniel C.
    General Manager
    Bayou Mobile Sound

Leave a Comment

Name (required)

E-mail (required, will not be published)

Website