5 Replies Latest reply on Apr 7, 2009 10:08 AM by David Stiller

    Creating ActionScript CuePoints

    yevri Level 1
      I have ActionScript Cuepoints working fine by clicking on the imported video instance and adding actionscript cuepoints. But we keep getting new video and I have to put the cuepoints back in every time. So I was hoping to add cuepoints and their times to this script instead. Can I do that with the FLVPlayback? The script is attached.



        • 1. Re: Creating ActionScript CuePoints
          David Stiller Level 2

          yevri,

           

          > I was hoping to add cuepoints and their times to this
          >  script instead. Can I do that with the FLVPlayback?

           

              You can, and the  FLVPlayback component makes it convenient by way of its addASCuePoint()  method.  (If you look up the FLVPlayback class entry of the ActionScript 2.0  Components Language Reference, you'll find this method.)

           

              By the looks  of it, your FLVPlayback instance name is vid, so assuming that's true, your  code might look something like this:

           

          var cue:Object = new  Object();

           

          // first cue point
          cue.time = 2.444;
          cue.name =  "save";
          cue.type = "actionscript";
          vid.addASCuePoint(cue);

           

          //  second cue point
          cue.time = 5.786;
          cue.name =  "americans";
          vid.addASCuePoint(cue);

           

          // third cue point
          cue.time =  12.002;
          cue.name = "howmuch";
          vid.addASCuePoint(cue);

           

          //  etc.

           

              I assume, for this example, that you're using ActionScript 2.0,  based on the code you showed already.  Notice that in my suggested code,  I've
          declared a generic Object instance named "cue", which is just an  arbitrary name.  The FLVPlayback component expects this cue point object to  be
          formatted in a certain way, which corresponds to the data you can  alternatively provide with the Component Inspector panel; namely, the cue  point needs a time value, a name, and a type (here, "actionscript").  In the  code I've shown, I only set the .type property once, because it keeps the  value "actionscript" until you change it.  The other properties, .time and  .name, are changed for each cue point, then passed into the FLVPlayback  instance, vid, by way of the addASCuePoint() method.

           

              You can  follow this code by the cuePoint event handler you already have in place,  and it works fine (just tested it here).  Note, though, that you can  *significamtly* reduce the complexity of your event handler by doing away  with the repeated if() statements.  Here's how:

           

          >  if (cues.info.name  == "save") {
          >  slides.gotoAndPlay("save");
          >  }

           

              By  happenstance, it looks like you've matched the names of your cue points to  the names of your frame labels.  This is a really good thing!  So really,  you don't have to check what the .name value is (here, "save"), and then  manually enter that same value ("save") into the gotoAndPlay() method. The  value of the expression cues.info.name *is* "save", so you can just pass in  the expression.  Check it out:

           

          vidList = new  Object();
          vidList.cuePoint = function(cues:Object):Void {
             slides.gotoAndPlay(cues.info.name);
          };
          vid.addEventListener("cuePoint",  vidList);

           

          ... and that replaces your numerous if() statements, because  rather than checking the value and then typing it in by hand, you're simply  passing that value into the gotoAndPlay() method.  Does that make  sense?

           


          David Stiller
          Co-author, Foundation Flash CS4 for  Designers
          http://tinyurl.com/dpsFoundationFlashCS4
          "Luck  is the residue of good design."

          • 2. Re: Creating ActionScript CuePoints
            yevri Level 1

            Hi David,

             

            Thanks so much for your thorough explanation. This is exactly what I was looking for. I was hoping Flash allowed such "short cuts" but I hadn't found that info anywhere by doing searches. I think I get it and I'll try it out and post my results. Also, looks like you have a book for sale - which looks like a good one. If I want to buy that, should I just click on the link in your signature?

             

            Thanks!

            • 3. Re: Creating ActionScript CuePoints
              David Stiller Level 2

              yevri,

               

                   Glad to help! 

               

              > I was hoping Flash allowed such "short cuts" but I hadn't found

              >that info anywhere by doing searches.

               

                   The real trick, I think, to looking up programming topics in the Help docs is to start from large to small, paying particular attention to what object(s) you're dealing with.  In this case, you're dealing with the FLVPlayback component.  In ActionScript, everything you can describe can be described as an object, and objects are defined by classes.  In ActionScript 2.0, component classes are listed in the Components Language Reference, while the rest of the classes are listed in the ActionScript 2.0 Language Reference.  In ActionScript 3.0, both normal classes and component classes are listed in the ActionScript 3.0 Language Reference.

               

                   Once you find the class entry you're looking for, start thinking about what exactly you're looking for.  Is it a characteristic of the object (such as a movie clip's width or height)?  If so, look under the properties heading.  Is it something the object can do?  Look under the methods heading.  If it's something the object can react to, look under the events heading.  In the AS3 reference, you'll want to click the hyperlink that says "Show inherited public properties" (or methods, or events).

               

              > Also, looks like you have a book for sale - which looks like a good

              > one.

               

                   Thanks!

               

              > If I want to buy that, should I just click on the link in your signature?

               

                   Yes.  That's a link to my Amazon referrals account, which means I'll get a dollar (or something like that) if you purchase the book.  Of course, you don't have to do it that way ... this book, and my other two, are also available in walk-in stores.

               

               

              David Stiller
              Adobe Community Expert
              Dev blog, http://www.quip.net/blog/
              "Luck is the  residue of good design."

              • 4. Re: Creating ActionScript CuePoints
                yevri Level 1

                Great advice, David. I have implemented that and it works great. One more thing that's related (if you have time). The video in this project has an alpha channel using Apple Animation codec. When I preview it on importing, it only shows one frame and won't show the whole video, so I have to run the video separately and clock the cuepoints, write the times down, then create cuepoints with ActionScript. I would love to be able to preview and put the cuepoints in at the exact times. Is there a way to import video with an alpha channel and still see the preview so you can embed cuepoints accurately?

                 

                As an alternative, in order to try to sync better, I have imported the audio to my "slides" movieClip so I can sync the animation to that, then put cuepoints in and test, then get rid of the audio and publish. I noticed when I play it on my local machine, it is in sync, but when I post to a server, the video plays faster than the timeline of the movieClip even though they are both set to 15 frames per second. Why would this be?

                 

                Thanks!

                • 5. Re: Creating ActionScript CuePoints
                  David Stiller Level 2

                  yevri,

                   

                  > The video in this project has an alpha channel using Apple Animation

                  > codec. When I preview it on importing, it only shows one frame and

                  > won't show the whole video

                   

                       Interesting.  I can't say that I've encountered that with alpha video (at least, not that I remember).  In what way are you previewing the video?

                   

                  > Is there a way to import video with an alpha channel and still see the

                  > preview so you can embed cuepoints accurately?

                   

                       Something in the recesses of my mind is telling me that recent versions of Flash do allow you to preview video inside the authoring tool, but that might just be a neuron misfiring.   If this is possible, I should think it's equally possible with normal content and content that has an alpha channel.

                   

                       To be sure, you can use the Import Video wizard to add cue points visually.  (Slide a playhead back and forth to actually see individual frames of the video content, then add cue points based on that.)  This works as long as you're encoding as the older FLV format (F4V doesn't support "baked in" cue points).  In my experience, this works with alpha and non-alpha content.  Is this the workflow you're experimenting with?

                   

                  > As an alternative, in order to try to sync better, I have imported the audio

                  > to my "slides" movieClip so I can sync the animation to that

                   

                       If you go this route, make sure to set your imported audio to "Stream" in the Property inspector (click the frame in which the audio first appears).  Stream locks the audio in-step with the timeline, while Event loads the audio fully into memory before playing it all at once -- which means it can get out of sync.  This is why animators use the Stream setting for cartoon lip synching.

                   

                  > I noticed when I play it on my local machine, it is in sync, but when I post

                  > to a server, the video plays faster than the timeline of the movieClip even

                  > though they are both set to 15 frames per second. Why would this be?

                   

                       In a case like this, you're using a workaround, or hack.  It's a potentially useful hack in some cases, but the trade-off is that you're likely to get out of sync, simply because video frames and timeline frames are two different beasts.  I wish I could give you a more technical answer than that, but just speaking from work exerience, cue points are the best way go for this sort of thing.  Let the video content do what it does best -- that is, synch its own tightly coupled video/audio tracks -- and let the timeline do its own thing, connecting the two with a cue point handler.

                   

                   

                  David Stiller
                  Co-author, ActionScript 3.0 Quick Reference Guide
                  http://tinyurl.com/dpsAS3QuickReferenceGuide
                  "Luck is the residue of good design."