15 Replies Latest reply on Jul 15, 2008 10:29 AM by erlendbv

    Closed Captioning

    yevri Level 1
      I'm trying to create closed captioning for an FLV playing in my Flash file. I've looked at tutorials on Lynda.com and used that exact code but I get errors - I've checked a bunch of times to make sure I've typed it in correctly and I think I have. Can you see why I'd get errors with this code (errors and code pasted below) and can anyone suggest how I should do this? I plan to create ActionScript cuepoints and when it hits the cuepoints, display text for that section of video.


      import fl.VideoEvent
      import fl.video.MetadataEvent;

      vid.addEventListener(MetaDataEvent.CUE_POINT, cueText);

      function cueText(e:MetadataEvent();void{
      var cuePointName = e.info.name;
      if(cuePointName=="one"){
      info.text = "one is the lonliest number";
      }else if(cuePointName=="two"){
      info.text = "two can be as sad as one";
      }
      }

      ERRORS:
      The class or interface 'fl.video.MetadataEvent' could not be loaded.
        • 1. Re: Closed Captioning
          Level 7
          yevri,

          I notice that in your addEventListener() method, you gave
          "MetadataEvent" a capital D. If that's the issue, it doesn't especially
          seem to match the error message you got (at least, to me), but it's easy
          enough to test. :)


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


          • 2. Re: Closed Captioning
            yevri Level 1
            Thanks for the reply, David. I changed that and it didn't help, but I appreciate you checking my code!
            • 3. Re: Closed Captioning
              Level 7
              yevri,

              > Thanks for the reply, David. I changed that and it didn't
              > help, but I appreciate you checking my code!

              Are you still getting an error message? If so, what is it?


              David Stiller
              Contributor, How to Cheat in Flash CS3
              http://tinyurl.com/2cp6na
              "Luck is the residue of good design."


              • 4. Re: Closed Captioning
                yevri Level 1
                Still getting the same three errors:
                The class or interface 'fl.video.MetadataEvent' could not be loaded.
                Identifier expected
                • 5. Re: Closed Captioning
                  yevri Level 1
                  For some reason the errors aren't all staying in the post.

                  The class or interface 'fl.video.MetadataEvent' could not be loaded.
                  Identifier expected
                  last one is unexpected }
                  • 6. Re: Closed Captioning
                    Level 7
                    yevri,

                    > The class or interface 'fl.video.MetadataEvent' could not be loaded.
                    > Identifier expected
                    > last one is unexpected }

                    The code you're posting is ActionScript 3.0, so I'm wondering if your
                    FLA file is configured for that version of the langauge. (This is the
                    ActionScript 1.0/2.0 forum, for example ... could it be that your FLA is
                    configured for ActionScript 2.0?)


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


                    • 7. Re: Closed Captioning
                      FrankErazo
                      Yevri:

                      Here's what I do to put captions on my FLVs.

                      Step #1: In addition to the layer with your video, add two more layers
                      a) caption
                      b) action

                      Step #2: Paste the following into your Action layer:

                      var captions:Array;

                      var captionsXML:XML = new XML();
                      captionsXML.ignoreWhite = true;

                      captionsXML.onLoad = function():Void {
                      captions = this.firstChild.childNodes;

                      for(var i:Number = 0; i < captions.length; i++) {
                      myVid.addASCuePoint(captions .attributes.start, captions.firstChild.nodeValue);
                      };

                      };

                      //replace my_caption_file.xml with your own xml filename
                      captionsXML.load("my_caption_file.xml");
                      myVid.addEventListener("cuePoint", onCuePoint);

                      function onCuePoint(evntObj:Object):Void {
                      txtCaption.text = evntObj.info.name;
                      };

                      Step #3: Add a dynamic text to the caption layer and give it the name txtCaption.

                      Step #4: Here's how your caption file should be formatted.

                      <?xml version="1.0" encoding="iso-8859-1"?>
                      <captions>
                      <caption start="000.0"> </caption>
                      <caption start="006.5"></caption>
                      <caption start="020.5"></caption>
                      <caption start="030.0"></caption>
                      <caption start="045.0"></caption>
                      <caption start="060.0"> </caption>
                      </captions>

                      Put whatever you want to show up as the caption between the caption tags.

                      The way I make sure the caption shows up at the exact time the line is read I look at the timeline in my video editor. I take the seconds and the frame count (1-29). Do some simple math (frame count/30) for the decimal value and you're done.

                      Let me know if this works for you.

                      BTW...I got this off of Flash's Developer community a while back before it got swallowed up by Adobe. Whew!!
                      • 8. Re: Closed Captioning
                        Level 7
                        Yevri,

                        This indeed looks as if you're mixing ActionScript 2.0 with ActionScript
                        3.0, which would sum up your issue right there. They can't be mixed in the
                        same SWF file.

                        > captionsXML.onLoad = function():Void {
                        > captions = this.firstChild.childNodes;

                        For example, these lines are AS2 (you can tell by the uppercase "V" in
                        "Void").

                        In your original post, you had code like this:

                        vid.addEventListener(MetaDataEvent.CUE_POINT, cueText);

                        ... which is AS3 (you can tell by the uppercase CUE_POINT event constant).

                        To move forward, you'll have to decide -- from a bird's eye view -- what
                        language you want to develop this project in as a whole. Then you'll have
                        to revise all code to suit that version of the language (cue points are
                        possible in AS2 as well as AS3).

                        Does that steer you in the right direction?


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


                        • 9. Re: Closed Captioning
                          yevri Level 1
                          Thanks for the code and advice, FrankErazo. Is this actionscript 2 or 3? I planned to use ActionScript 2 and my FLA is set up for that, but was grabbing code without thinking about version (thanks for the warning, David).

                          • 10. Re: Closed Captioning
                            Level 7
                            > Thanks for the code and advice, FrankErazo.

                            Heh, looks like I replied to FrankErazo thinking it was Yevri (doh!).

                            > Is this actionscript 2 or 3?

                            FrankErazo's code is AS2.

                            > I planned to use ActionScript 2 and my FLA is set up for that, but
                            > was grabbing code without thinking about version (thanks for the
                            > warning, David).

                            Sure thing. Your code, from your first post, is AS3.


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


                            • 11. Closed Captioning
                              yevri Level 1
                              Thanks for the help David. FrankErazo, thanks for the script. I haven't quite got it to work yet. I get nothing when I run the file until I change the instance name of the flv playback component to "myvid" - should that be the instance name of the FLVPlayback component? When I give it that instance name, I get this error: 1002: Illegal cue point: time must be number

                              Also, do I make the dynamic text field a movieClip with the instance name of txtCaption? I've tried it that way and with no movieClip with an instance name and without the instance name but with the variable name as txtCaption. Can you clarify?

                              Any ideas on what I'm doing wrong? In case anyone wants to view these, the FLAs are posted here: http://sullyville.com/nba/flas.zip

                              There is an intro.flv file up there to if you need that: http://sullyville.com/nba/intro.flv


                              Here is what I have in the first frame of the timeline:
                              var captions:Array;

                              var captionsXML:XML = new XML();
                              captionsXML.ignoreWhite = true;

                              captionsXML.onLoad = function():Void {
                              captions = this.firstChild.childNodes;

                              for(var i:Number = 0; i < captions.length; i++) {
                              myvid.addASCuePoint(captions.attributes.start, captions.firstChild.nodeValue);
                              };

                              };

                              //replace my_caption_file.xml with your own xml filename
                              captionsXML.load("captions.xml");
                              myvid.addEventListener("cuePoint", onCuePoint);

                              function onCuePoint(evntObj:Object):Void {
                              txtCaption.text = evntObj.info.name;
                              };
                              • 12. Re: Closed Captioning
                                yevri Level 1
                                I still haven't gotten the script to work for closed captioning.

                                I've put the script in like FrankErazo suggested, but it's not working and I'm not sure what I'm doing wrong.
                                I get nothing when I run the file until I change the instance name of the flv playback component to "myvid" - which I was assuming was what the script was referencing as the instance name of the FLVPlayback component. When I put that as the instance name, I get this error: 1002: Illegal cue point: time must be number. If I go into the xml file and take the quotes out of the first caption start time, that error goes away, but I still get nothing in the dynamic text field.

                                That's the first issue. The second issue is that I'd like to use cue points to move the playback head in a movieClip so that while the person in the video is talking, I can have phrases fly in, charts be displayed, etc. Can you modify that script to show me how to do that? Let's say the movieClip would be named "Slide" - or whatever you want.

                                Thanks for the help - I'm under the gun to get this finished!
                                • 13. Re: Closed Captioning
                                  yevri Level 1
                                  I worked on this and right now I'm doing this for making animations appear during the video, though I'm sure there is a much better way.

                                  I'm putting actionscript cuepoints into various parts of the flv then creating a movieClip called "slides" and putting animations, etc. in there along the timeline with stops between them. Then using the script below on the first frame.

                                  var vidList:Object = new Object();

                                  vidList.cuePoint = function(cues) {
                                  slides.play();
                                  }

                                  vid.addEventListener("cuePoint",vidList);


                                  • 14. Re: Closed Captioning
                                    FrankErazo Level 1
                                    Yevri:

                                    Go to my website (www.frankerazo.com) and click on the link labeled My Work. On that page, you will find a zip file labeled nature.zip. That file contains all the information you need.

                                    Since you said you were on a time crunch, I figured sending you the FLA would be better than having you spend time trying to figure out how to make one work. Besides, you can always go back and look a this later to study.

                                    And yes...I am using ActionScript 2.0 with Flash 8.

                                    Let me know if it works...enjoy!
                                    • 15. Closed Captioning
                                      erlendbv Level 1
                                      Dear FrankErazo.

                                      Thanks for providing the FLA-source on your site. The code is really neat, and you seem to have control of what you're doing ( in contrast to my coding sessions based on trial and error :) ).

                                      I have a question for you (or anybody else who can contribute). This may be slightly off-topic, but it's still closely related;

                                      I have a task to provide exactly what you have provided, but for a movieclip. I will load an external SWF into the movieclip, and present subtitles as they are shown in your project, based on cue points in the SWF. The problem, of course, is that I can't use the FLV-playback (as I'm loading a SWF, not an FLV). And that means that I can't use addASCuePoint(), because it is based on the FLV-playback component. I think. What is the alternative when using the oldschool loadMovie into a movieclip?

                                      What can I do to reach this goal? All suggestions will be greatly appreciated, as I'm pushed towards a deadline and find myself short of the intelligence to figure out a solution. :( - Thanks in advance!

                                      *EDIT* I've been doing some research, and here is the solution I've decided to use;
                                      i) I'll load the XML in a similar fashion to FrankErazo's sample.
                                      ii) I'll run an onEnterFrame-function with a for-loop checking the _currentframe of the movieclip (divided on framerate to get seconds, like the cue-points in the XML).
                                      iii) If the current position matches the captions[ i ].attributes.start, I'll fill the text-field with the specified caption.

                                      Works like a charm! FrankErazo; Thanks for pointing me in the right direction, and for generously making your source code available for review. :)