4 Replies Latest reply on Apr 5, 2008 8:41 AM by Greg Dove

    Netstream in a for loop

    Clockwork_Killa
      I need a way to create multiple netstreams, because the code that I have so far will only play one video.
      I tried various methods of adding "i" onto the netConn and netStream, but all I got were errors. So is there any way of incorporating the netstream into the for loop, or any other way to create multiple netstreams?
      Thanks

        • 1. Re: Netstream in a for loop
          Greg Dove Level 4
          maybe try using local variables, otherwise it looks like you're reassigning a new instance to the same variable each time.

          var netConn:NetConnection = new NetConnection();

          and
          var netStream:NetStream = new NetStream(netConn);
          • 2. Netstream in a for loop
            Greg Dove Level 4
            thinking about it a little more, I'm not sure if that would work either. perhaps you would have to create the references within separate scope or somehow create new variable names within the current scope. If the above doesn't work you could put the references on the timeline of the newly created clips perhaps, maybe try it like this:

            _root["myClip"+i].netConn=new NetConnection();
            _root["myClip"+i].netConn.connect(null);
            _root["myClip"+i].netStream = new NetStream(_root["myClip"+i].netConn);

            _root["myClip"+i].vid1.attachVideo(_root["myClip"+i].netStream);
            _root["myClip"+i].netStream.play(myVid);

            That could be made easier to read by capturing a local variable reference to the new clip from the attachMovie call and using that instead of _root["myClip"+i]
            • 3. Re: Netstream in a for loop
              Clockwork_Killa Level 1
              quote:

              Originally posted by: GWD
              thinking about it a little more, I'm not sure if that would work either. perhaps you would have to create the references within separate scope or somehow create new variable names within the current scope. If the above doesn't work you could put the references on the timeline of the newly created clips perhaps, maybe try it like this:

              _root["myClip"+i].netConn=new NetConnection();
              _root["myClip"+i].netConn.connect(null);
              _root["myClip"+i].netStream = new NetStream(_root["myClip"+i].netConn);

              _root["myClip"+i].vid1.attachVideo(_root["myClip"+i].netStream);
              _root["myClip"+i].netStream.play(myVid);

              That could be made easier to read by capturing a local variable reference to the new clip from the attachMovie call and using that instead of _root["myClip"+i]

              That works just fine. Thank you very much!

              • 4. Re: Netstream in a for loop
                Greg Dove Level 4
                You're welcome.