5 Replies Latest reply on Dec 7, 2009 2:20 PM by abeall

    NetConnection.connect(null) + BitmpaData.draw = sandbox error

    abeall Level 3

      I don't get it. Can someone explain why this:

       

      import flash.display.*;
      var bmp:BitmapData = new BitmapData(Stage.width, Stage.height, true, 0);;
      attachBitmap(bmp, 2, "auto", true)
      
      var nc:NetConnection = new NetConnection();
      nc.connect(null);
      var ns:NetStream = new NetStream(nc);
      vid.attachVideo(ns);
      
      bmp.draw(_root);
      
      ns.play("video.flv");
      

       

      Throws this error:

       

      *** Security Sandbox Violation ***
      Connection to null halted - not permitted from file:///~test.swf

       

      Despite the error description, the video plays fine, it's the bmp.draw which fails. If I move the ns.play before the bmp.draw, it works?!

        • 1. Re: NetConnection.connect(null) + BitmpaData.draw = sandbox error
          kglad Adobe Community Professional & MVP

          the draw() method requires data from your video.  exactly why that triggers a cross-domain issue when no video is loaded, i'm not sure.

          • 2. Re: NetConnection.connect(null) + BitmpaData.draw = sandbox error
            abeall Level 3

            The weird thing is the error doesn't happen in Flash 8, only Flash CS3 or CS4.

             

            I'm in a bit of a pickle because the NetStream is most of the time closed. I suppose I could do ns.play("") instead of ns.close()? How hacky, though...

             

            What I would really like to do is remove the video attachment, but I haven't found a way to do that either. There's attachVideo but no removeVideo. attachVideo(null) doesn't work, attachVideo(false) removes the video but the error still happens.

            • 3. Re: NetConnection.connect(null) + BitmpaData.draw = sandbox error
              kglad Adobe Community Professional & MVP

              (i thought this was an academic question.)

               

              if you're trying to create a bitmap of the stage before the video loads, use the draw method before your netconnection.connect() statement.  if you're trying to create a bitmap that includes something from the video, use the draw method some time after the ns.play() method.  both should work.

              • 4. Re: NetConnection.connect(null) + BitmpaData.draw = sandbox error
                abeall Level 3

                (no sorry this is a real problem I'm having)

                 

                I'm basically just trying to draw the stage, I don't care about capturing the video. I capture the stage before the video and blur it behind the video to create a modal video popup. So drawing the background bitmap before the NC is easy, *except* that I also draw the bitmap when the stage resizes which might happen in the middle of a video playing.

                 

                Likewise using draw() only after ns.play is actually not straight forward, because the ns is often closed via ns.close(). Only at select points does the ns.play get called, but the video instance is always on the stage, and the lingering attachVideo(ns) seems to cause this error when ns is closed.

                 

                Unfortunately it's way too late to put everything on the main timeline in a container MovieClip and have the video popup in a sibling MovieClip, but one way or another it looks like I will need to re-order things to avoid this error... probably I will remove the video instance from the stage and use attachMovie only when needed to avoid a situation where ns is closed but video has been attachVideo to it.

                • 5. Re: NetConnection.connect(null) + BitmpaData.draw = sandbox error
                  abeall Level 3

                  Here's my workaround:

                   

                  emptyNetStream();
                  bmp.draw(_root);
                  attachNetStream();
                  
                  function attachNetStream(){
                      // attach proper NetStream
                      preview_mc.video_mc.vid.attachVideo(ns);
                  }
                  function emptyNetStream(){
                      // attach a blank NetStream, this ensures BitmapData.draw works
                      // even if the real NetStream is closed, which would normally
                      // cause a sandbox error
                      var nc2 = new NetConnection();
                      nc2.connect(null)
                      var ns2 = new NetStream(nc2);
                      ns2.play("");
                      preview_mc.video_mc.vid.attachVideo(ns2);
                  }