OK, here's how to do this, in both AS3 and AS2
First some basics.
I used Flash CS3 Video Encoder to encode the FLV so I could embed my own cuepoints. What you name them doesn't matter. Just make certain you adjust the action script below to the cuepoint name you choose. In most cases I'll put one at the beginning (as a navigation) and one at the end (as an event). In this case I called the one at the beginning "begin" and the one at the end "finished". Here's a screen shot:
It's so much easier to create your own cuepoints as you encode your video. Unfortunately, sometimes you are just handed an FLV without cuepoints. Fortunately you can create your own using ActionScript. I've never had to do it that way, but there's plenty of tutorials out there that explain how if you need to.
One last note - remember that your FLV HAS to be imported to the first frame of your timeline. If you can't do that in your movie you'll have to create it in it's own movie and then load that movie into your main one.
Now that I have my FLV encoded with cuepoints added, simply open a new blank Flash file (AS3 or AS2, whichever you prefer) and import your FLV to stage using the FLVPlayback component (requires Flash 8 or higher).
Give your FLVPlayback component whatever instance name you want. In this case I used "my_FLVPlybk" (which you'll see is pretty common if you ever look through tutes.)
If you are working with ActionScript 3, on the same frame as your FLV add this code:
import fl.video.*;
//set up the cuepoint listener
my_FLVPlybk.addEventListener(MetadataEvent.CUE_POINT, cp_listener);
function cp_listener(eventObject:MetadataEvent):void {
//trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
//trace("Cue point name is: " + eventObject.info.name);
//trace("Cue point type is: " + eventObject.info.type);
//listen for the end cuepoint which I named "finished" during encoding
if (eventObject.info.name == "finished") {
var URLReq:URLRequest = new URLRequest("http://www.xmission.com/~emailbox/whycat.htm");
try {
//here's our redirect
navigateToURL(URLReq, "_self");
} catch (e:Error) {
trace(e);
}
}
}
- import fl.video.*;
-
- //set up the cuepoint listener
- my_FLVPlybk.addEventListener(MetadataEvent.CUE_POINT, cp_listener);
- function cp_listener(eventObject:MetadataEvent):void {
- //trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
- //trace("Cue point name is: " + eventObject.info.name);
- //trace("Cue point type is: " + eventObject.info.type);
-
- //listen for the end cuepoint which I named "finished" during encoding
- if (eventObject.info.name == "finished") {
- var URLReq:URLRequest = new URLRequest("http://www.xmission.com/~emailbox/whycat.htm");
- try {
- //here's our redirect
- navigateToURL(URLReq, "_self");
- } catch (e:Error) {
- trace(e);
- }
- }
- }
If you are working with AS 2 here is your code:
//to use getURL it has to be in an on or onClipEvent so we use onClipEvent (load)
onClipEvent (load) {
import mx.video.*;
//set up the cuepoint listener
var listenerObject1:Object = new Object();
listenerObject1.cuePoint = function(eventObject:Object):Void {
var cuePtName = eventObject.info.name; //variable for cuepoint name
//listen for the end cuepoint which I named "finished" during encoding
if (cuePtName == "finished") {
//do the redirect
getURL("http://www.xmission.com/~emailbox/whycat.htm", "_self");
//trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
//trace("Cue point name is: " + eventObject.info.name);
//trace("Cue point type is: " + eventObject.info.type);
}
};
my_FLVPlybk.addEventListener("cuePoint", listenerObject1);
}
- //to use getURL it has to be in an on or onClipEvent so we use onClipEvent (load)
- onClipEvent (load) {
- import mx.video.*;
-
- //set up the cuepoint listener
- var listenerObject1:Object = new Object();
- listenerObject1.cuePoint = function(eventObject:Object):Void {
- var cuePtName = eventObject.info.name; //variable for cuepoint name
- //listen for the end cuepoint which I named "finished" during encoding
- if (cuePtName == "finished") {
- //do the redirect
- getURL("http://www.xmission.com/~emailbox/whycat.htm", "_self");
-
- //trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
- //trace("Cue point name is: " + eventObject.info.name);
- //trace("Cue point type is: " + eventObject.info.type);
- }
- };
- my_FLVPlybk.addEventListener("cuePoint", listenerObject1);
- }
I added a few comments to help explain what's going on.
The end result is the same in both cases:
AS 3 exampleAS 2 example(my apologies for the length of the video. It was the shortest one I had available. If you don't want to watch the whole thing just use the slider to scrub near the end - I set it to redirect to a related page on why cats do things).
"The web is a dominatrix. Every where I turn, I see little buttons ordering me to Submit."
Play sports pools and discuss sports topics at Boasting Rights Sports Forum
Get paid to write articles - www.associatedcontent.com