1

PDF ファイルをダウンロードするために、自分のサイトにフラッシュ ダウンロードがあります。

var myfileReference:FileReference = new FileReference();
down_mc.visible = false;
down_comp.visible = false;

var myRequest:URLRequest = new URLRequest("GEORGIA INCORPORATED.pdf");
myfileReference.addEventListener(IOErrorEvent.IO_ERROR, ioError);
output_txt.text = "";

function ioError(event:ErrorEvent):void {
output_txt.text = "Sorry that there is an IO error during the file downloading. The error is:" + "\n" + event;

}

myfileReference.addEventListener(ProgressEvent.PROGRESS, fileDownloadProgress);

function fileDownloadProgress(event:ProgressEvent):void {

    down_mc.visible = true;
}
myfileReference.addEventListener(Event.COMPLETE, fileDownloadCompleted);

function fileDownloadCompleted(evt:Event):void {
    down_mc.visible = false;
    down_comp.visible = true;

}

function downloadFile (event:MouseEvent):void {

    try {
        myfileReference.download(myRequest);
    } catch (error:SecurityError) {

        downloading. The error is:" + "\n" + error; 

    } catch (error:IllegalOperationError) {

        downloading. The error is:" + "\n" + error; 
    }
    }
b1.addEventListener(MouseEvent.CLICK, downloadFile);

問題は、ダウンロードしているファイルの名前を変更し、拡張子を .pdf に変更して、ファイルを使用できなくしたい人がいるということです。クライアントが拡張子を変更しないようにする方法はありますか?

4

1 に答える 1

0

純粋な as3 では、ユーザーに特定の拡張子でファイルを保存するように強制することはできません。それを行う唯一の方法は、FileStream オブジェクトを介して制御できる Air を使用することです (ファイル名を選択できます)。

Airでそれをしたい場合は、次のことができます:

// Assuming you get your pdf raw data
var pdfData : ByteArray;

var f : File = File.desktopDirectory.resolvePath("myPdf.pdf");

// When user have select a file
f.addEventListener(Event.SELECT, function(e:Event):void{
    var targetFile : File = e.target as File;

    // Check if the selected file have pdf extension
    if(targetFile.nativePath.substr(targetFile.nativePath.length - 4) != ".pdf")
        // If not, add it
        targetFile = new File(targetFile.nativePath + ".pdf");

    // Save the file
    var fs : FileStream = new FileStream();
    fs.open(targetFile, FileMode.WRITE);
    fs.writeBytes(pdfData);
    fs.close();
});

// Ask user to save a file (by default on user desktop)
f.browseForSave("Save PDF");
于 2013-03-22T10:31:44.587 に答える