12 Replies Latest reply: Jun 27, 2008 7:39 AM by Digital_Mercenary RSS

    Play video in frame 1 then go to frame 2 on complete

    Stephen Pickering122 Community Member
      I am very new to Flash and especially ActionScript... I just want a video which is in frame 1 (I imported an avi which was then encoded and has a skin) to play and at the end of the video simply go to the next frame (or a new video, whatever is easiest) which will have a "Play Again" or "Buy DVD" buttons.
      I found the following code from another forum but I do not know how to use it. The playback component is "FLVPlayback" which is what is listed but it looks like "myListener" needs to be changed as it is black (not blue in the code). Do I create a "Listener"? And how?
      Thank you!
        • 1. Re: Play video in frame 1 then go to frame 2 on complete
          Stephen Pickering122 Community Member
          I've searched for 2 weeks on how to do this but all the answers are so simple but similar to the as3 I have above, however it does not work for me. I am missing something but I cannot for the life of me figure out what I'm missing.
          If I import an FLV file it appears in my library as FLVPlayback. I assume this is the player for the flv video. Do I need to give it an Instance Name?
          • 2. Re: Play video in frame 1 then go to frame 2 on complete
            Stephen Pickering122 Community Member
            Also, as I'm sure you've guessed I have several Compiler Errors, obviously because I do not know what to alter and what to leave. I am trying so many ways that the errors are always different. I would be glad to post though if it would help anyone assist me.
            Thank you!
            • 3. Re: Play video in frame 1 then go to frame 2 on complete
              Digital_Mercenary Community Member
              I'm no GURU by any means, but I can show you how I would personally go about this with AS3. I would use an flv for my video format and import it into the swf via a NetStream Object. Also, you can just type in "NetStream", "Video", or "NetConnection" in your 'Actions Frame', highlight it, and hit 'F1'. The 'Help' window will open straight to whatever class you have highlighted when you hit F1. You can read up on methods and properties associated with that class and learn more. Here's the code. I hope this helps!
              • 4. Re: Play video in frame 1 then go to frame 2 on complete
                Stephen Pickering122 Community Member
                Digital_Mercenary, I'll try this tonight, thanks!
                • 5. Re: Play video in frame 1 then go to frame 2 on complete
                  Stephen Pickering122 Community Member
                  Please excuse my ignorance but what do I replace and what do I keep? I tried the help file but the example it uses are quite different than any of the "solutions."
                  Looking at other examples and using tutorials it looks like I need to have some "import flash.events.NetConnection" imports. Is your cosde complete or is it just an example? Do I replace any of your code (other than "my_directory/my_videos/myMovie.flv"?)
                  I haven't given up yet and I'm still reading but just seems like a wild goose chase where there isn't a solid answer or working example to just look at for reference. I found all kinds of example but they are all so complex that I don't know what I'm looking at.
                  Thank you again.
                  • 6. Re: Play video in frame 1 then go to frame 2 on complete
                    Andrei1 Community Member
                    Hi,

                    You always have to import whatever classes you use with practically no exception. You can import individual classes or entire packages that contain your classes.

                    You need to know what packages contain the class you intend to use. In your case NetConnection resides NOT in events package but in the net package. So you want to import flash.net.NetConnection.

                    Events associated with NetConnection reside in the flash.events package. The most useful events in terms of the playing video are flash.events.NetStatusEvent,

                    Also, you want to get parameters of the video you are playing. This is accomplished by invoking onMetaData method on your client which can be anything (either a separate class or a current display objects you are working in).

                    It may be confusing at first but then the logic is becoming clearer as you keep working on it.

                    Actually, my question is: do you use FLVPlayback or you write your own code that plays video utilizing Video class? You have to handle these approached differently. What I wrote about classes pertains to the case when you utilize Video class, NetConnection and NetStream.

                    Also, where does your flv reside on the server relative to your swf? Or do you embed it at authoring time?
                    • 7. Re: Play video in frame 1 then go to frame 2 on complete
                      Digital_Mercenary Community Member
                      Andrei1,
                      The only time I've ever imported classes is when writing my own class in an AS3 file or importing a class I've already written in an AS3 file into the actions panel in an FLA. I've only been coding with AS3 for about 4 months. I coded with AS2 for a year. AS3 is almost like learning from scratch. Should I be importing classes (other than custom classes I have written) when coding straight to the actions panel in an FLA? Is it absolutely necessary only when you are creating instances of the Video, NetConnection, or NetStream classes?

                      Is this taken?,
                      Yes, it is very confusing, and many times, over-complicated. I have seen thus far that there seem to be three or four different ways to approach almost any given task code wise within ActionScript. The code that I attached to my previous post is the entirety of some code that I have actually used to do exactly what you are trying to accomplish. Ask three other guys the same question, and you'll probably learn at least two more ways to code the same thing. I usually just pick one and decide to be happy that I made it work and stick with it. You may as well accept confusion, research, and trial and error as a way of life. I have. Don't worry though.......as soon as you begin to fully understand a particular concept or objective, there will be another problem waiting for you with open arms. Just read my next question for Andrei1.

                      Andrei1,
                      Perhaps you can help me. I am trying to stream a 20 sec 1.9K flv from a server as part of a splash page I am building for a client. I'm using the NetStream method I described to 'Is this taken?'. The swf, html, and flv files are all in the same directory; both on my PC and on the server. I also have a preloader coded which seems to be working great. I can open the html file with the embedded swf file (which uses a NetStream to play the flv) locally in IE and I have no problem. Works great. When I deploy these to the server, everything loads great and plays for 10sec then freezes. I can wait all day under the assumption I'm having some kind of buffering issue, but no dice. When it freezes that's it. I can even wait for a minute and refresh the page just to see if indeed it is a buffering issue, and hope that maybe the entire flv is in the browser's cache and that it will now play in its entirety. It still freezes in the same place. I rendered the flv from AfterEffects with a bitrate of 1.7K at 640X480.
                      Could the bitrate be an issue? If I go any lower I seem to sacrifice image quality. The preloader seems to do it's thing, but I've got to be missing something. Is it possible that this could be related to what you mentioned about always importing classes? I'm at my whit's end on this one.

                      • 8. Re: Play video in frame 1 then go to frame 2 on complete
                        Andrei1 Community Member
                        Digital_Mercenary,

                        You have to import classes that you use. What import does is pointing to the location of the classes that are called to action - it doesn't really uses classes and doesn't physically places classes inside your application until you ask flash to. If you don't import classes Flash doesn't know what you are trying to accomplish and it should throw an error. it may not be always the case on the main timeline but if you use classes - you have to be explicit about where the classes you use are.

                        As for your issue with the flv playback - could you please show your code? We will try to take it from there.

                        Also, on the remote server flv MIME type should be made explicitly known to the server - it is not by default. Do you have any control over the server configuration? On your local machine - do you open the HTML using a server or directly - c:\\ and all this stuff?

                        Unfortunately I cannot help you with video encoding for I have done it a couple of times only and, frankly, have no idea how different encoding ways affect flash performance although my guess would be it should not matter unless the file is corrupted. If you don't find a solution until tomorrow - I will ask the guys at work who handle video encoding. Since your video plays at least partially I don't think there is an issue with importing classes.

                        I assume you use a progressive video - not streaming.

                        In any case - please post your code first.


                        • 9. Re: Play video in frame 1 then go to frame 2 on complete
                          Digital_Mercenary Community Member
                          The flv is loaded through a movieClip named GardenWalk which contains this code:

                          // this part is pretty cut and dry
                          var introConnection:NetConnection = new NetConnection();
                          introConnection.connect(null);
                          var introStream:NetStream = new NetStream(introConnection);
                          var metaIntro:Object = new Object();
                          metaIntro.onMetaData = onMetaData;
                          introStream.client = metaIntro;
                          var intro:Video = new Video();
                          introStream.play("anAffairOfTheHeart_Intro_small.flv");
                          intro.attachNetStream(introStream);
                          addChild(intro);

                          function onMetaData(data:Object):void
                          {

                          }

                          The code that I have placed on the main timeline is as follows:
                          frame1 - preLoader - just a movieClip with a turning circle and the word 'Loading' visible on the stage. All other elements are present, but not visible:

                          var total:Number = stage.loaderInfo.bytesTotal;
                          var loaded:Number;
                          var loadProgress:Number;
                          gardenWalk.alpha = 0; //gardenWalk is my flv Loading MovieClip
                          bigFrame.alpha = 0; //bigFrame is just a MovieClip used as a border

                          loadProgress = setInterval(checkProgress, 10);

                          function checkProgress():void
                          {
                          loaded = stage.loaderInfo.bytesLoaded;

                          if(loaded >= total)
                          {
                          clearInterval(loadProgress)
                          gotoAndPlay(2);
                          }

                          }
                          stop();

                          Frame2 animation and flv display:

                          wreath.alpha = 0; // wreath is part of thre client's logo
                          affairText.alpha = 0; // affairText is part of the logo as well

                          gardenWalk.scaleX = 1.8;
                          gardenWalk.scaleY = 1.45;
                          gardenWalk.x += 85;
                          gardenWalk.y -= 10;
                          gardenWalk.alpha = 1;
                          bigFrame.alpha = 1;

                          var fadeCounter:Number = 0;
                          var checker:Number;
                          var fader:Number;
                          var wreathFader:Number;
                          var wreathCounter:Number = 0;
                          var wreathScale:Number;

                          gardenWalk.mask = videoMask;

                          checker = setInterval(checkTime, 10)
                          function checkTime():void
                          {

                          if(gardenWalk.introStream.time >= 15)
                          {
                          clearInterval(checker);
                          var fader:Number = setInterval(fadeThis, 10)
                          }
                          }
                          // At 15 sec the intro flv and 'frame' fade out and client's logo fades in

                          function fadeThis():void
                          {
                          gardenWalk.alpha -=.02;
                          bigFrame.alpha -=.02;
                          fadeCounter++;
                          switch(fadeCounter)
                          {
                          case 10:
                          wreathFader = setInterval(wreathFade, 10);
                          break;

                          case 50:
                          gardenWalk.alpha = 0;
                          bigFrame.alpha = 0;
                          gardenWalk.x -= 1000;
                          bigFrame.x -= 1000;
                          clearInterval(fader);
                          break;
                          }
                          }
                          // I used a 'switch' to time two events with 1 interval

                          function wreathFade():void
                          {
                          wreath.alpha +=.02;
                          wreath.scaleX += .0025;
                          wreath.scaleY += .0025;
                          wreath.x += 2;
                          wreathCounter++;
                          if(wreathCounter >= 50)
                          {
                          clearInterval(wreathFader);
                          wreathCounter = 0;
                          wreathScale = setInterval(wreathShrink, 3);
                          }
                          }
                          // the wreath fades in, scales up and moves to the right

                          function wreathShrink():void
                          {
                          wreath.scaleX -= .0005;
                          wreath.scaleY -= .0005;
                          wreath.x += 1.35;
                          wreath.y += .25;
                          affairText.alpha += .02;
                          wreathCounter++;
                          if(wreathCounter >= 50)
                          {
                          clearInterval(wreathScale);
                          }
                          }
                          /*
                          the wreath scales down some, and moves down a little and to the right as the client's name 'An Affair of the Heart' (A big Arts and Crafts Festival) fades in.
                          */
                          stop();

                          The server that I am using is the Yahoo server that handles my personal website. I just upload the files to a 'test' folder, and test them of course, before delivering them to a client. Here is a link to the page:

                          http://theserialartist.com/RichMediaSamples/anaffairoftheheart/an_affair_of_the_heart.html

                          also

                          http://theserialartist.com/RichMediaSamples/anaffairoftheheart/anAffairOfTheHeart.swf

                          When I open the html directly, from the c:\\ I have no problem at all. When I open it via http, the problem arises. Making the MIME type explicity known to the server is a concept I'm not familiar with, and I have this little feeling that this may be the culprit.

                          I just embedded the audio in the timeline becuase its a pretty small MP3. The flv itself is stopping completely! Otherwise, the checkTime function would see the 15 sec point and start the fade into the logo. This has worked for me well in the past. Was I just lucky until now? Thanks for taking time to give me a hand. I appreciate it. In the meantime, I'm going to do a little research about MIME type in relation to flv's. THANKS!
                          • 10. Re: Play video in frame 1 then go to frame 2 on complete
                            Digital_Mercenary Community Member
                            By the way Andrei1, I think I understand the value of importing classes.....even when you're only working on the main timeline. If you try to communicate with a swf outside of the timeline you're working on, Flash won't know where the classes inside the swf you are trying to communicate with are. If I had imported the classes into the swf I was trying to communicate with in the first place, I would'nt have had the problem.
                            • 11. Re: Play video in frame 1 then go to frame 2 on complete
                              Andrei1 Community Member
                              Hey,

                              Sorry I am too tired to look at the AS after 9 hours of work - I hope you'll understand :-) I promise I will look into it tomorrow morning. A brief look at your code doesn't reveal any problems.

                              I still think that the server issue should be weeded out. The thing is that not all the hosts welcome videos and audio. In addition to the possibility that they didn't set up the server to recognize FLV they may have a very special way to deliver the data which may actually block files that exceed certain size or split the data into pieces that don't go together when they arrive (they may even arrive at asynchronous times). Based on the fact that your video stops at precise same point - chances are my gut feelings are correct. I would definitely never trust Yahoo or any other huge hosts to handle my media needs. Not for political reasons but because they cater to the below average wants plus they are policing content too much. HTML/JS pages are fine but when more sophisticated stuff is concerned - I would look for more competent service.

                              Andrei
                              • 12. Re: Play video in frame 1 then go to frame 2 on complete
                                Digital_Mercenary Community Member
                                That only makes too much sense. Thanks for your help Andrei1. Much appreciated!