Help me forward to new page at end of Flash video
November 11, 2007 8:42 AM   Subscribe

How do I get Flash to play a FLV and then go to particular URL when it's done?

I'm working on a project where people view a Flash video (just an FLV file with no skin or anything else) and then get forwarded to another page when it's done. I need them to see the whole video, so I can't just put a text link for the next page. I don't know Flash especially well, and the code that I've found online keeps giving me demands for an onClipEvent handler. Ideas?
posted by aaronetc to Computers & Internet (5 answers total) 1 user marked this as a favorite
 
I think you load the FLV into the flash file, and play it using as many frames in the SWF as are in the FLV. In the last frame, you put an actionscript which contains a "getURL" function call. Or something along those lines.
posted by Steven C. Den Beste at 9:29 AM on November 11, 2007


You could always write a little javacsript with a timer that's the same length as the video, then a window.location redirect. Not an elegant sollution though.
posted by ReiToei at 9:54 AM on November 11, 2007


Yes, that would work. A more robust solution would be to code the whole thing in Actionscript (this would allow you to switch videos) and not use the timeline.

It code will be slightly different, depending on whether you're using AS 2.0 (Flash 8 and 9) or AS 3.0 (Flash 9). I'm going to assume that you're using Flash's flvPlayback component for video -- not because I like it (I don't) -- but because it will make this answer easier to write. Rolling-your-own-video-player, while a good idea, would derail this thread.

So I'm assuming a one-frame-long fla/swf with the flvPlayback component on stage, and I'm also assuming that you've given the component the instance name "flvPlayer." Finally, I'm going to assume AS 2.0.

The code goes in frame one.

var strVideoPath:String = "http://path.to.video.flv";
var strUrl:String = "http://url.to.link.to.when.video.is.complete";
var objFlvListener:Object = new Object();

//see up functions to run when video is loaded
//and complete
objFlvListener.ready = readyFunction;
objFlvListener.complete = completeFunction;
flv.addEventListener("ready", objFlvListener);

//start the ball rolling by loading the video
flv.autoPlay = false; //make sure readyFunction controls play
flv.contentPath = strVideoPath; //see above

function readyFunction(objEvent:Object):Void
{
flv.play();
}


function completeFunction(objEvent:Object):Void
{
getUrl(strUrl);
}
posted by grumblebee at 10:00 AM on November 11, 2007


Response by poster: I don't know why I didn't think to just extend the timeline and put getURL in the last frame, but that worked fine, even though I wouldn't want to do it on any kind of large rollout. grumblebee's script is close to what I was finding elsewhere (relying on the "complete" event), so I'll give that a try as well, since I'll probably have to do this again. Thanks, all.
posted by aaronetc at 10:38 AM on November 11, 2007


Using a long timeline is a brute force solution, but it's easy. As we engineers say, "A stupid solution that works isn't stupid."
posted by Steven C. Den Beste at 11:17 AM on November 11, 2007


« Older Organise my writing   |   Donde esta Ed Naylor: Pedal Steel Guitar... Newer »
This thread is closed to new comments.