22 Replies Latest reply on Jun 20, 2012 11:43 AM by MARKARKARK

    Flv preloader

    MARKARKARK Level 1

      Hello,

       

      I have a project in as2.  It is a quiz that has a video asking the question, one for an correct answer and one for an incorrect answer.  This quiz has 25 question, with 75 videos possible.  I am having problems with the video sticking on the later questions.  I have another discussion on here and have done quite a few things to try to fix this.  My question is, is there a way I can preload a flv file that I have on my website to my flash project, so it is completely loaded before it is needed.  In other words  If question 1 is on frame 100 and with the three frames I will need for my question, correct answer and incorrect answer, I put question 2 on frame 110.  Could I have the 3 videos start to load for question 2 while the user is still on question 1 on frame 100?  So by the time the user answers the question and sees the video answer question 2  videos would be fully loaded.  I have looked for tutorials about this, but have only found ways to make a status bar. 

       

      Thanks for your help.

       

       

      Mark.

        • 1. Re: Flv preloader
          adninjastrator Level 4

          So the .flv is embedded into the main timeline?

          What do you mean by "problems with the video sticking on the later questions"?

          Are you testing locally and having these problems? or are you testing from a Web server?

          Are you having any sync problems? wrong vid for the question, etc?

          Adninjastrator

          • 2. Re: Flv preloader
            MARKARKARK Level 1

            I have all of the videos uploaded to my website.  When I imported my videos I imported to stage and then gave the address where they are on my website.  I am having problems because I am using cue points to bring up the questions and moving to the next question.  In other words, when the video is playing in the question it will when it reaches the cue point advance to the next frame where the various questions with answers would be, the buttons also appear behind the questions.  When a button is selected it either takes the user to the correct answer or incorrect answer video.  After these videos play, the cue point takes them to the next question.  The problem, is in later questions the videos delay in playing and sometimes don't play.   This stops the quiz from continueing.   I can right click and go back to the previous frame that ususally gets it moving, but I can't expect the average user to do this.  Other than that I am not having any other sync problems.  I have been publishing this, and downloading the swf to my site so I can test it over the internet on a non public page on my site.

            • 3. Re: Flv preloader
              adninjastrator Level 4

              I think that I am understanding most of what you are trying to do.

              So question 1 plays and then a correct or incorrect answer video plays... and so forth and so on???

              Are you using the FLVPlayback component for all the videos?

              and there are 75 vids? Are there cuepoints in each vid? and that cue point moves to another point on the main timeline and in that frame there is a new FLVPlayback component playing the next question?

              Does every video have to download and play in total?

              So all of question 1 vid and all of answer 1 vid has to download and play? or can you answer before the end of question 1 and do you have to watch all of answer 1 before moving to answer 2?

              If you go thru the quiz very slowly, giving all videos plenty of time to download, do you still have delay problems with later questions?

              Are there any other vids loading if you are on Question 10, for example? are 8 & 9 still loading?

              • 4. Re: Flv preloader
                MARKARKARK Level 1

                I have not used the FLVPlayback component.  I just started experimenting with it a few minutes ago.  Each question and answer have has 1 cue point.  You can answer the question midway through each question, the answer must play out completely.  With every question either the correct or incorrect answer video will play.  So in the course of 25 questions, 50 videos will play.  However there are correct and incorrect responses so the total video choice is 75.  I do not know if other videos are still loading, how can I find this out?  It seems to stick regardless of the speed you answer.   With the FLVPlayback component.  I have dragged the component on the stage openened the componenet inspector and copied the address of the video.  Is there anything else I need to do to make this work?  Now that I look at this, I think it is accomplishing the same thing as to the way I was originally importing. 

                • 5. Re: Flv preloader
                  adninjastrator Level 4

                  I am not mentioning FLVPlayback as a recommendation, rather as a clarification.

                  There are only 3 ways to display Flash video that I am aware of.

                  1. embed into timeline

                  2. use the FLVPLayback

                  3. use NetStream

                  I'm still not sure which method you are using. The reason this is important to understand is that the method of controlling the video is different for each.

                  If the user does not have to wait until the question plays out fully

                  You can answer the question midway through each question,

                  that means that the answer video could start playing while the previous question video is also loading.

                  Over a period of time, say by question 13 or 14, the lag could be because all those question video have to finish downloading... as well as all the answer videos.

                  Unless you explicitely stop the download process, each video that is called and starts to download, will continue to download until completion. Pausing or stopping the video may not be stopping the download.

                  In the cue points and button actions, is there an explicit command to stop the download, not just the "pause" the video?

                  Here is an example of what I am talking about:

                  http://www.mrfilmbiz.com/

                  Open the page and you'll see a video loading status bar. Above the word "Hollywood" you'll see a "Skip Intro" button. Click the button before the intro loads fully and you'll see that the download is stopped. Now click the "Play Intro" button and you'll see the video start downloading again.

                  Pausing the video stops the video from playing yet does NOT stop the downloading.

                  This example illustrates that button actions can and should include explicite instructions to FIRST stop the downloading and then do whatever other button action you want.

                  So your answer buttons should include as the first line of instruction.... stop the video downloading.

                  Here is the actionscript for the "Skip Intro" button.... the video is being played via the NetStream method I mentioned earlier

                  skip_btn.onRelease = function() {

                  ns.close();

                  gotoAndStop("end");

                  }

                  The important part is that ns.close(); is used as the very first line of button action. This closes the NetStream, stopping the download of the rest of the file.

                  I think your lag is due to having so many videos that must download completely. By the time you get to questions 15... there are multiple earlier videos that have not yet finished downloading... hence there is just not enough bandwidth available to accomplish that PLUS download a new question.

                  Of course none of this is has to do with "pre-loading". Even if you do preload, there is still the problem of having to download all 75 vids completely.... which may be beyond the bandwidth/time constraints of some users.

                  So I still recommend adding the stop download line to the buttons.

                  And here is a loader you may want to look into:

                  http://www.greensock.com/loadermax/

                  Best wishes,

                  Adninjastrator

                  • 6. Re: Flv preloader
                    MARKARKARK Level 1

                    Thank you so much for your help.   The way I am bringing my video into my project is...

                     

                    1.  I convert my video to an flv from premiere pro with adobe media encoder, I thn load that to a file in my website.

                    2.  In my flash project I select the keyframe I wish and select file-import-import-import to stage.

                    3.  It gives me the choice to embed the video or select a video already posted on a site.  I have to this point selected the videos posted on my site. 

                     

                    The problems I have had with the loaders so far is that they are all actionscript 3, my project is actionscript 2.  Can I use this in an project with actionscript 2?  I'm sorry I have limited knowledge. 

                     

                    I think you are correct about the other videos still loading.  I assume I need to load this code in the frame the video is on with the cue points etc.

                     

                    I don't know what netstream is, I will see what I can find.

                     

                    Thanks again,

                     

                    Mark. 

                    • 7. Re: Flv preloader
                      adninjastrator Level 4

                      The code to stop loading the video needs to go on the answer button (as I illustrated above).... so you answer "A" or "B".... which ever answer you choose it first stops the downloading of the current video BEFORE it even plays the answer video.

                      You will find that using NetStream is a much more versatile and powerful means of interacting with video than the FLVPlayback (which I think you are using now).

                      There are some great AS2 NetStream video tutorials here:

                      http://www.gotoandlearn.com/

                      Scroll to the very bottom of the page. Thsoe video tutorials will show you how to create your own custom NetStream vid player.

                      Best wishes,

                      Adninjastrator

                      • 8. Re: Flv preloader
                        MARKARKARK Level 1

                        Thanks I will play with this tonight and post the results tomorrow. 

                         

                        Thank you so much, I can't tell you what a help this has been.

                         

                        Mark.

                        • 9. Re: Flv preloader
                          MARKARKARK Level 1

                          I have been working with the NetStream and have watched the tutorials.  Only one problem now, my cue points don't work. the script I have been using is:

                           

                          stop();

                          var listenerObject:Object = new Object();

                          listenerObject.cuePoint = function(eventObject:Object):Void {

                          // Put any code you like here

                          trace("Cue point name: " + eventObject.info.name);

                          trace("Cue point type: " + eventObject.info.type);

                          if(eventObject.info.name=="nn"){

                          gotoAndStop(150);

                          }

                          }

                          n2.addEventListener("cuePoint", listenerObject);

                           

                          Thank you again for your help.

                           

                          mark.

                          • 10. Re: Flv preloader
                            adninjastrator Level 4

                            Been awhile since I've worked with cue points but I think there is a difference in how you use cue points between NewStream and the FLVPlayback component (which you were using before).

                            Here is a working version I use to load a couple different .swf files (each which happens to hold another video).

                            ns.onCuePoint = function(evt:Object){
                                trace(evt.name);
                                trace(evt.time);
                                if(evt.name == "play_vid1") {
                                    trace("YO!Loading wide_holder!");
                                    wide_holder.loadMovie("rm/images/black_bear.swf");
                                }

                                if(evt.name == "play_vid2") {
                              trace("YO!Loading standard_holder!");
                                    standard_holder.loadMovie("rm/images/sqis.swf");
                                }
                            };

                            Off the top of my head I believe it was this line that I had to change to work with NetStream:

                            function(eventObject:Object):

                            notice the slight difference in syntax.

                            Sorry I don't have any more info. I'd suggest you Google "using Flash cue points with NetStream (NOT the FLVPlayback component)".

                            Best wishes,

                            Adninjastrator

                            • 11. Re: Flv preloader
                              MARKARKARK Level 1

                              Thanks for your response.  I have googled several but have a hard time making out what it is, there is no clear tutorial or explaination.  I did have a question, you wrote, "The important part is that ns.close(); is used as the very first line of button action. This closes the NetStream, stopping the download of the rest of the file."  Should the code you had provided be modified to put this at the top?  The line provided is in the second line of the script.

                               

                              Thanks again,

                               

                              Mark.

                              • 12. Re: Flv preloader
                                adninjastrator Level 4

                                answer_btn.onRelease = function() {

                                ns.close();

                                gotoAndStop("A10");

                                }

                                Remember that this is the answer button action. The first line of code just defines that it's a function. "answer_btn" is the instance name of the button.

                                The very first line of the function is

                                ns.close();

                                BEFORE the timeline moves on to the frame labeled "A10"... a name I am using for the answer to Question 10.

                                For example... I see the question 10 video... then I choose an answer, before the end of the whole question video. The button action stops the question video from downloading further and takes me directly to answer 10.

                                Thinking more about using cue points:

                                the answer must play out completely

                                If the only reason you are using cue points is to detect the end of the Answer 10 video and then move to Question 11... you don't even need cue points for that.

                                Add this code to the same actionscript you are using to play the Answer 10 video... below the netstream player code:

                                ns.onStatus = function(info) {

                                  if(info.code == "NetStream.Play.Stop") {

                                  trace("Video complete")   

                                  gotoAndStop("Q11"); 

                                  }

                                }

                                ........when NetStream info funtion detects that the Answer 10 video has stopped at the end...

                                trace "Video complete"

                                and then gotoAndStop (or gotoAndPlay) Question 11.

                                All the above code is actual, working code. You may need to change instance names, etc to match what you are using, but you should be able to adapt this code to your needs.

                                Best wishes,

                                Adninjastrator

                                • 13. Re: Flv preloader
                                  MARKARKARK Level 1

                                  Thank you so much for your help.  The reason I am using cue points is that the video plays on a layer and I have at the cue point the timeline advance so question text is seen when the caracature asks the question.  It then either has an end cue or not.  Questions have no end cue, but the answers do.  The question pulls up the text midway through the video.   I don't need to que a video, but to have the video play on a layer and advance to another keyframe so something on another layer will show within the video.  So if my video plays of someone asking a question, the actual text will appear on screen in front of the video when cued. 

                                   

                                  I have tried to take the script you provided earlier and take out the

                                   

                                  "

                                  trace("YO!Loading wide_holder!");
                                          wide_holder.loadMovie("rm/images/black_bear.swf");
                                      }

                                      if(evt.name == "play_vid2") {
                                    trace("YO!Loading standard_holder!");
                                          standard_holder.loadMovie("rm/images/sqis.swf");"

                                   

                                  and substitute it with "gotoAndStop (100)"  but this did not work.   I hate to keep asking for your help, but would you have any idea how to do this, I haven't been able to figure it out. 

                                   

                                  Thanks again,

                                   

                                  Mark.

                                  • 14. Re: Flv preloader
                                    adninjastrator Level 4

                                    I see that you are using frame numbers... I'd suggest that in the future you use frame labels instead. For example, when debugging the code gotoAndStop(100); is not as meaningful as gotoAndStop("Q10");

                                    Note that you need the double quotes when using frame labels.

                                    OK, here is a working NetStream cue point:

                                    var ns:NetStream = new NetStream(nc);

                                    video_screen.attachVideo(ns);

                                    /* Name of your video, with correct path, goes here */

                                    ns.play("my_video.flv");



                                    ns.onCuePoint = function(evt:Object){

                                        trace(evt.name);

                                        trace(evt.time);

                                        if(evt.name == "jump_100") {

                                            trace("YO !Jump to 100!");

                                            gotoAndStop(100);

                                        }  

                                    };

                                    Reading this code:

                                    set a new variable "ns" which is a new NetStream

                                    attach a video to "video_screen"... the instance name of the video on the stage

                                    now use that variable "ns" to play a video with file name "my_video.flv"

                                     

                                    use ns to listen for an "event" type cue point Object

                                    when the cue point is detected trace the event name and time

                                    if the event name is exactly equal to "jump_100"

                                    then trace "YO !Jump to 100!"

                                    and then gotoAndStop at frame 100

                                     

                                    For this exact code to work, your NetStream variable must be named "ns"

                                    In the video you play, there must be a cue point of the "Event" type with the name "jump_100"

                                    There must be at least 100 frames in the timeline.

                                     

                                    Take it in small steps;

                                    First make sure you can play the video using NetStream ... that's all.

                                    Next, add the trace to detect the cue point... if you can't detect it, of course it won't do anything.

                                    Only after you can successfully play the video and detect the cue point, should you attempt the cue point action (jump to frame 100).

                                     

                                    Hope this gets you closer.

                                    Best wishes,

                                    Adninjastrator

                                    • 15. Re: Flv preloader
                                      MARKARKARK Level 1

                                      Thanks, you are great!

                                      • 16. Re: Flv preloader
                                        MARKARKARK Level 1

                                        Thank you so much, this works great.  I have taken the information  you had supplied in earlier posts and have been able to figure out what to do.  This was the last puzzle piece.  Thank you so much, you are a lifesaver.

                                         

                                        Mark.

                                        • 17. Re: Flv preloader
                                          adninjastrator Level 4

                                          You are most welcome!

                                          Glad you got it working.

                                          If you found any of my posts as answering or helpful, please mark them so others looking for help will also know where to look.

                                          Best wishes,

                                          Adninjastrator

                                          • 18. Re: Flv preloader
                                            MARKARKARK Level 1

                                            Hello,

                                             

                                            One final problem,  I have an introduction that has 5 cue points, when I use the code it only works if I have 1 cue point, is there a way to make it recognize, cue 1, cue 2 etc. and go to the appropriate keyframe with each.

                                             

                                            Thanks,

                                             

                                            Mark.

                                            • 19. Re: Flv preloader
                                              adninjastrator Level 4

                                              Use "if" statements, as in

                                              ns.onCuePoint = function(evt:Object){
                                                  trace(evt.name);
                                                  trace(evt.time);
                                                  if(evt.name == "play_vid1") {
                                                      trace("YO!Loading wide_holder!");
                                                      wide_holder.loadMovie("rm/images/black_bear.swf");
                                                  }

                                                  if(evt.name == "play_vid2") {
                                                trace("YO!Loading standard_holder!");
                                                      standard_holder.loadMovie("rm/images/sqis.swf");
                                                  }
                                              };

                                              if cue 1 do this

                                              if cue 2 do this, etc.

                                              Best wishes,

                                              Adninjastrator

                                              • 20. Re: Flv preloader
                                                MARKARKARK Level 1

                                                The following is the code I was trying to use.  You can see I have added another cuepoint.  When I do this it doesn't work.  I see you have things labled standard and wide for loading movies, is there some way I need to add an additional title to these?

                                                 

                                                 

                                                var nc:NetConnection = new NetConnection();

                                                nc.connect(null);

                                                var ns:NetStream = new NetStream(nc);

                                                i1.attachVideo(ns);

                                                ns.play("http://www.mywebsite.com/video/seg4/intro.flv");

                                                ns.onCuePoint = function(evt:Object){

                                                    trace(evt.name);

                                                    trace(evt.time);

                                                    if(evt.name == "c1") {

                                                        trace("YO !Jump to 25!");

                                                        gotoAndPlay(25);

                                                    } 

                                                };

                                                ns.onCuePoint = function(evt:Object){

                                                    trace(evt.name);

                                                    trace(evt.time);

                                                    if(evt.name == "c2") {

                                                        trace("YO !Jump to 38!");

                                                        gotoAndStop(38);

                                                    } 

                                                };

                                                 

                                                What I wanted this to do was to play the movie on a layer and go to frame 25 while the movie plays.  On another layer I have text which comes up on frame 25, it has a tween to frame 37.  At the next cue point "c2"  I wanted it to go to frame 38 where a highlight punctuates the text.

                                                 

                                                Thanks again,

                                                 

                                                Mark.

                                                • 21. Re: Flv preloader
                                                  adninjastrator Level 4

                                                  Use multiple "if" statements in the same onCuePoint function... just one function, multiple choices for that function

                                                  ns.onCuePoint = function(evt:Object){

                                                      trace(evt.name);

                                                      trace(evt.time);

                                                      if(evt.name == "c1") {

                                                          trace("YO !Jump to 25!");

                                                          gotoAndPlay(25);

                                                      }

                                                  if(evt.name == "c2") {

                                                          trace("YO !Jump to 38!");

                                                          gotoAndStop(38);

                                                      }

                                                       MORE IF STATEMENTS CAN GO HERE....

                                                  };

                                                  If the cue is c1, do this, if c2 do this other thing, etc. down a list of if statements

                                                  You can have as many if's as needed and you could also add an "else" statement (if the cue doesn't match any of the if statements) at the end, before the final closing bracket if you wanted.

                                                  • 22. Re: Flv preloader
                                                    MARKARKARK Level 1

                                                    Worked great!  Thanks.