下载多个flash文件



我有一个Flash应用程序与一个数据网格充满了文件名,我希望用户能够从该网格检查多个文件,并下载到他的本地驱动器。这些文件存储在数据库中的blob字段中,我使用php来检索它们。我试图使用URLLoader和filerreference下载文件,但它不工作。下面是代码:

private function downloadSelected():void {
            var dp:Object=dg.dataProvider;
            var cursor:IViewCursor=dp.createCursor();
            while( !cursor.afterLast )
            {
                //Alert.show(cursor.current.IsChecked.toString());
                if (cursor.current.IsChecked.toString()=="true") {
                    //myAmostras.push(cursor.current.CodBarras.toString());
                    //nenhumaAmostra=false; 
                var u:URLRequest= new URLRequest;
                    var variables:URLVariables = new URLVariables();            
                    variables.amostras = cursor.current.CodBarras.toString();
                    variables.disposition="attach";
                    u = new URLRequest("savereports.php");
                    u.method = URLRequestMethod.POST;
                    u.data=variables;

                    pdfloader = new URLLoader();
                    //pdfloader.dataFormat=URLLoaderDataFormat.BINARY;
                    pdfloader.addEventListener(Event.COMPLETE, completeHandler,false,0,true);
                    pdfloader.addEventListener(IOErrorEvent.IO_ERROR, downloadError); 

                    try {
                        pdfloader.load(u);
                    } catch (error:Error) {
                        Alert.show("Unable to load requested document.");
                    }
                }
                cursor.moveNext();
            }   
        }
        private function downloadError(event:Event):void {
            Alert.show("Error loading file");
        }

        private function completeHandler(event:Event):void {
            var myFileReference:FileReference = new FileReference();
            myFileReference.save(event.target.data);
        }
有谁能帮我一下吗?

使用filerreference。下载而不是URLLoader,我可以下载在数据网格中选择的第一个文件,但其他抛出异常错误#2041

        private function downloadSelected():void {
            var dp:Object=dg.dataProvider;
            var cursor:IViewCursor=dp.createCursor();
            var i:int=0;
            while( !cursor.afterLast )
            {
                if (cursor.current.IsChecked.toString()=="true") {
                    var u:URLRequest= new URLRequest;
                    var variables:URLVariables = new URLVariables();            
                    variables.amostras = cursor.current.CodBarras.toString();
                    variables.disposition="attach";
                    u = new URLRequest("savereports.php");
                    u.method = URLRequestMethod.POST;
                    u.data=variables;
                    try {

                        var myFileReference:FileReference = new FileReference();
                        myFileReference.download(u,cursor.current.CodBarras.toString()+".pdf");
                    } catch (error:Error) {
                        Alert.show("Unable to load " + cursor.current.CodBarras.toString()+".pdf" );
                    }
                }
                cursor.moveNext();
            }   
        }

相关内容

  • 没有找到相关文章

最新更新