0

ファイル名で満たされたデータグリッドを持つ Flash アプリケーションがあり、ユーザーがそのグリッドから複数のファイルをチェックして、ローカル ドライブにダウンロードできるようにしたいと考えています。ファイルはデータベースの blob フィールドに保存され、php ro を使用してそれらを取得します。URLLoader と FileReference を使用してファイルをダウンロードしようとしていますが、機能していません。コードは次のとおりです。

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);

        }

誰でもこれについて私を助けることができますか?

4

1 に答える 1

0

URLLoader の代わりに FileReference.download を使用すると、データグリッドで選択された最初のファイルをダウンロードできますが、他のファイルは例外 Error#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();
            }   
        }
于 2013-03-13T17:56:10.260 に答える