Problem with save mode

Hello all, help me solve one problem in my project:

i have function:

private function onPreviewComplete(event:MouseEvent) : void {
            var jscommand:String = "window.open('http://www.quip.us/test/form.php','win','height=400,width=300,toolbar=no,scrollbars=yes');"; 
            var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);"); 
            navigateToURL(url, "_blank"); 
           
/////save block
            var data_bmp:BitmapData = new BitmapData(backgroundLayer.width,backgroundLayer.height);
            data_bmp.draw(backgroundLayer);
            var png_image_data:ByteArray = PNGEncoder.encode(data_bmp);

            var url_req:URLRequest = new URLRequest("http://www.quip.us/test/img_create.php");
            url_req.data = png_image_data;
    

            url_req.method = URLRequestMethod.POST;

            var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
            url_req.requestHeaders.push(header);
             var u:URLLoader= new URLLoader();
             u.load( url_req ); 

function work when you click button, then load popup window and need in background copy images in server (if separate - save work, but in function save not work) - why? help me with this

and i have other function with my button:

private function onBgLoadInit(e:Event) : void {
            btnSend = new PreviewBtnSend();
            btnSend.x = 650;
            btnSend.y = 96;
            btnSend.buttonMode = true;
            btnSend.tabEnabled = false;
            btnSend.addEventListener(MouseEvent.CLICK, onPreviewComplete, false, 0, true);
            btnSend.addEventListener(MouseEvent.MOUSE_OVER, onPreviewButtonRollOver);
            btnSend.addEventListener(MouseEvent.MOUSE_OUT, onPreviewButtonRollOut);
        }

If you comment out the block to save, a pop-up works without problems. Help me solve problem
Thanks