![]() |
![]() |
||||||
|
|||||||
| Tags: cuepoint, help |
![]() |
|
|||
|
I have a progresive flv with an instance name of myVideo which is already on
the stage and set to autoplay via the component parameters tab. When the video plays and gets to a cue point I want the flv to pause. Can anyone help me with my code? Is there a better way to do it? Here is what I have so far: var listener:Object = new Object(); listener.cuePoint = function(eventObject:Object):Void { if (eventObject.info.name == "cp1") { myVid.gotoAndStop("cp1"); } if (eventObject.info.name == "cp2") { myVid.gotoAndStop("cp2"); } if (eventObject.info.name == "s3") { myVid.gotoAndStop("cp2"); } vid.addEventListener("cuePoint", listener); |
| Sponsored Links |
|
|||
|
necie,
> When the video plays and gets to a cue point I want the flv > to pause. Can anyone help me with my code? Sure thing. > var listener:Object = new Object(); > > listener.cuePoint = function(eventObject:Object):Void > { > if (eventObject.info.name == "cp1") > { So far, so good. You're checking for the cue point name as it was supplied by you. > myVid.gotoAndStop("cp1"); > } Here's a significant problem. When you're dealing with video, you're either dealng with the NetConnection and NetStream classes, or you're dealing with the FLVPlayback class. Since you mentioned components, I'm guessing you're using FLVPlayback. It helps to understand that everything in ActionScript can be described in terms of an object. In this case, you're dealing with an FLVPlayback object. Objects are defined by their (usually namesake) classes. Think of a class as a recipe. Movie clips are defined by the MovieClip class; text fields by the TextField class; sounds by the Sound class, and so on. If you're formatting text, you'll want the TextFormat class, and so on. You get the idea. Classes generally describe one or more of the following three categories: properties (characteristics of the object), methods (things the object can do), and events (things the objectg can react to). You're using gotoAndStop(), which is an active term, basically a "verb." That means you're describing what the object can do ... in other words, a method. If you look up the FLVPlayback class, you'll find that the Methods heading does not contain a gotoAndPlay() method. That's a MovieClip method, which means it's something you can only instruct a movie clip to do. You will find a pause() method, though, and that's your ticket here. ![]() Obviously, when the video pauses, the cue points will stop, because they depend on the video actually rolling. So somewhere, you'll need to provide a mechanism for playing the video again. Maybe a button? David Stiller Co-author, Foundation Flash CS3 for Designers http://tinyurl.com/2k29mj "Luck is the residue of good design." |
|
|||
|
Wow, I'm reading your blog right now about FLV cue points. I get an email from
the adobe forum and it's you with some info to help me out. You are an incredible educator. I used the NetStream instead of FLVPlayback. I used your code from your blog and tweaked it for my files and I added the pause(). It worked great. Now to get to that play button. I need to add a keyboard event. The desired result is the end user can continue to play the video by pressing the right arrow button. I'm trying to NOT use buttons. Here's what I have so far and the playing of the netStream isn't working. var nc:NetConnection = new NetConnection(); nc.connect(null); var ns:NetStream = new NetStream(nc); videoPlayer.attachNetStream(ns); var listener:Object = new Object(); listener.onMetaData = function(evt:Object):void {}; listener.onCuePoint = function(evt:Object):void { ns.pause(); }; ns.client = listener; ns.play("CPVideo.flv"); stage.addEventListener(KeyboardEvent.KEY_DOWN, playVideo); function playVideo(event:KeyboardEvent):void { trace(event.keyCode); ns.play(); } |
|
|||
|
Wow, I'm reading your blog right now about FLV cue points. I get an email from
the adobe forum and it's you with some info to help me out. You are an incredible educator. I used the NetStream instead of FLVPlayback. I used your code from your blog and tweaked it for my files and I added the pause(). It worked great. Now to get to that play button. I need to add a keyboard event. The desired result is the end user can continue to play the video by pressing the right arrow button. I'm trying to NOT use buttons. Here's what I have so far and the playing of the netStream isn't working. var nc:NetConnection = new NetConnection(); nc.connect(null); var ns:NetStream = new NetStream(nc); videoPlayer.attachNetStream(ns); var listener:Object = new Object(); listener.onMetaData = function(evt:Object):void {}; listener.onCuePoint = function(evt:Object):void { ns.pause(); }; ns.client = listener; ns.play("CPVideo.flv"); stage.addEventListener(KeyboardEvent.KEY_DOWN, playVideo); function playVideo(event:KeyboardEvent):void { trace(event.keyCode); ns.play(); } |
|
|||
|
necie,
> Wow, I'm reading your blog right now about FLV > cue points. I get an email from the adobe forum and > it's you with some info to help me out. Heh, it's pretty neat when it works out that way. > You are an incredible educator. Thanks, necie! > I used your code from your blog and tweaked it for my > files and I added the pause(). It worked great. Now to > get to that play button. I need to add a keyboard event. Keyboard makes good sense; just keep in mind, the SWF won't respond to keyboard input (I think!) unless the SWF has focus. Test that to make sure. > Here's what I have so far and the playing of the netStream > isn't working. > stage.addEventListener(KeyboardEvent.KEY_DOWN, playVideo); > function playVideo(event:KeyboardEvent):void > { > trace(event.keyCode); > ns.play(); > } The structure of your code is fine, but that play() method is the culprit here. It needs at least one parameter, which tells the NetStream instance what file to play. Without that parameter -- as you've seen -- Flash doesn't know what you're asking for. The solution is to use the optional Boolean parameter of the pause() method. In your cue point handler, use ns.pause(true); ... then, in your keyboard handler, use ns.pause(false); -- that should do it! David Stiller Contributor, How to Cheat in Flash CS3 http://tinyurl.com/2cp6na "Luck is the residue of good design." |
|
|||
|
First of all please allow me to say thanks for helping me out. I've switched
the code using your suggestions but am getting errors on the ns.pause(true); and the ns.pause(flase); methods. Here is what I have: var nc:NetConnection = new NetConnection(); nc.connect(null); var ns:NetStream = new NetStream(nc); videoPlayer.attachNetStream(ns); var listener:Object = new Object(); listener.onMetaData = function(evt:Object):void {}; listener.onCuePoint = function(evt:Object):void { ns.pause(true); }; ns.client = listener; ns.play("CPVideo.flv"); stage.addEventListener(KeyboardEvent.KEY_DOWN, playVideo); function playVideo(event:KeyboardEvent):void { trace(event.keyCode);//i'm using this to see if I can get the number for the Right arrow key, not sure where to put that info yet but will deal with that later// ns.pause(false); } |
|
|||
|
necie,
> First of all please allow me to say thanks for helping me out. Sure thing. > I've switched the code using your suggestions but am getting > errors on the ns.pause(true); and the ns.pause(flase); methods. I see why, too -- and I should have taken better care with my previous reply! When you mentioned, in a previous post, you thought you were in the Actionscript 1 & 2 forum, I got it stuck in my head that you were using AS2, so my code suggestion was for the AS2 version of the NetStream class. The fact that your stage reference is lowercase (AS3), and that your keystroke event handlers use the KeyboardEvent class (AS3), should have reminded me that you're actually using ActionScript 3.0. So ... the Boolean parameter no longer applies. For AS3, use pause() -- no true/false parameter -- to pause your NetStream instance. Use resume() -- again, no parameter -- to resume it. David Stiller Co-author, ActionScript 3.0: The Quick Answer Guide for Flash Professionals http://tinyurl.com/2s28a5 "Luck is the residue of good design." |
|
|||
|
That worked just fine. Finally have a working video with cue point and keyboard
control. Kinda feel like Tom Hanks in Cast Away after he makes fire. Thanks so much for your help. And thanks for explaining the details so well. Perhaps one more question. I used the trace(event.keyCode); so that when I hit a key I could tell what number to use in the code. But where, and with what special syntax might I put these numbers. The space bar (39) will ns.pause(); at any time, while the cue points are predetermined pauses. The right arrow (32) will ns.resume(); the video. this is where I thought it would go, but it's not working: stage.addEventListener(KeyboardEvent.KEY_DOWN, <32>, playVideo); Am I on the right track? |
|
|||
|
necie,
> Kinda feel like Tom Hanks in Cast Away after he makes > fire. Thanks so much for your help. Ha, that's a great image! Sometimes I feel like he did when he had to knock out his tooth with the ice skates. > I used the trace(event.keyCode); so that when I hit a key > I could tell what number to use in the code. But where, and > with what special syntax might I put these numbers. You'll do that inside the event handler (your playVideo() function), and when you see how, it'll make perfect sense. > stage.addEventListener(KeyboardEvent.KEY_DOWN, <32>, playVideo); > > Am I on the right track? Wrong track. But check it out:function playVideo(event:KeyboardEvent):void { if (event.keyCode == 32) { // do the space bar thing } if (event.keyCode == whatever) { // do the whatever thing } } As an alternative to using a series of if() statements, you could use a switch() statement: function playVideo(event:KeyboardEvent):void { switch (event.keyCode == 32) { case 32: // do the space bar thing break; case whatever: // do the whatever thing break; case whatever2: // do the whatever2 thing break; } David Stiller Co-author, ActionScript 3.0: The Quick Answer Guide for Flash Professionals http://tinyurl.com/2s28a5 "Luck is the residue of good design." |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise