3 Replies Latest reply on Dec 8, 2006 4:15 AM by Newsgroup_User

    Loading streaming video w/ "onEnterFrame"

    infoVac Level 1
      The code works with the onPress function, but when i try to use onEnterFramenothing happens. Im trying to make the movie play as soon as the swf loads up. Im still very new to custom FLV players.
      This is the code that i used:

      //player.play_mc.onPress=function(){
      onEnterFrame=function(){
      myVideo_nc=new NetConnection(); // this creates a new variable and attaches the following object

      myVideo_nc.connect(null);//this tells as that you are not connecting using the Flash Communication Server
      // but will download the data from either a local hard drive or web address.

      newStream_ns=new NetStream(myVideo_nc);//New variable name this is another object class in AS and tells flash that you will
      //this case Video and will be using the netConnection parameters
      videoHolder.attachVideo(newStream_ns);//for this parameter enter the video source (the name of the new netStream object)


      newStream_ns.play("superhero2.flv");//enter the variable name of the stream object add path
      };



      P.S. if any one know a good tutorial on how to make a custom FLV player with actionscript 2.0 it would be much appreciated if a link was posted, and would also save me alot of time. thank you.
        • 1. Re: Loading streaming video w/ "onEnterFrame"
          Level 7
          infoVac,

          > //player.play_mc.onPress=function(){
          > onEnterFrame=function(){
          > myVideo_nc=new NetConnection(); // this creates a
          > new variable and attaches the following object

          By default, FLAs operate at a framerate of 12fps (frames per second).
          With the above code, you're instantiating a new NetConnection object 12
          times a second, for the duration of your movie! That's approximately once
          every 80 milliseconds. This is incredibly hard on the processor, and
          unnecessary, as you only need a single instance of NetConnection.

          If you want to trigger this in response to some event (such as a button
          press), I would instantiate the necessary objects once, simply by typing
          them directly to a keyframe of your scripts layer, then using an event
          solely to "make things move," so to speak.

          var myVideo_nc:NetConnection = new NetConnection();
          myVideo_nc.connect(null)
          var newStream_ns:NetStream = new NetStream(myVideo_nc);
          videoHolder.attachVideo(newStream_ns);

          These four lines set everything up. You're locked and loaded, and now
          all you have to do is pull the trigger. If you want to play the movie in
          response to a button, try this ...

          myButton.onRelease = function():Void {
          newStream_ns.play("superhero2.flv");
          }

          That's really all there is to it. :) If you don't care about the
          button, just invoke that play() method in the next line on its own:

          newStream_ns.play("superhero2.flv");


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


          • 2. Re: Loading streaming video w/ "onEnterFrame"
            infoVac Level 1
            Thak you very much. I have one more question though. I your code:

            myButton.onRelease = function():Void {
            newStream_ns.play("superhero2.flv");
            }

            What does "void" do?
            • 3. Re: Loading streaming video w/ "onEnterFrame"
              Level 7
              infoVac,

              > Thak you very much.

              Sure thing.

              > I have one more question though. I your code:
              >
              > myButton.onRelease = function():Void {
              > newStream_ns.play("superhero2.flv");
              > }
              >
              > What does "void" do?

              :Void (with a capital V) does the same thing as the :NetCnnection does
              in this line ...

              var myVideo_nc:NetConnection = new NetConnection();

              ... and that is, it defines a datatype for something. In the line with var,
              you're declaring a variable by the name of myVideo_nc, and the *type* of
              that variable is NetConnection (meaning, it's an instance of the
              NetConnection class).

              In the function definition, it lets the compiler know what datatype (if
              any) is returned by the function. In the case of the onRelease event
              handler, no value is returned, so the *type* returned is nothing ... aka
              Void.

              If for some reason the function returned a number (just making up an
              example), then you could do this:

              myButton.onRelease = function():Number {
              newStream_ns.play("superhero2.flv");
              return 5;
              }

              This sort of explicit datatyping isn't required, but it's a good habit
              to get into, because it helps the compiler help you.


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