2010-06-04 25 views

回答

0

如果您製作一個按鈕併爲其指定一個實例名稱iBtn_Download,則使其工作的代碼如下所示。只需將以下代碼粘貼到項目的時間軸中即可。只需將模板網站地址更改爲文檔所在的位置即可。

iBtn_Download.addEventListener(MouseEvent.CLICK, downloadDocument); 

function downloadDocument(_event:MouseEvent):void 
{ 
    var urlRequest:URLRequest = new URLRequest("http://www.yourwebsite.com/downloads/document.pdf"); 

    navigateToURL(urlRequest); 
} 
5

FileReference::download()

btn.addEventListener(MouseEvent.CLICK, promptDownload); 

private function promptDownload(e:MouseEvent):void 
{ 
    req = new URLRequest("http://example.com/remotefile.doc"); 
    file = new FileReference(); 
    file.addEventListener(Event.COMPLETE, completeHandler); 
    file.addEventListener(Event.CANCEL, cancelHandler); 
    file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); 
    file.download(req, "DefaultFileName.doc"); 
} 

private function cancelHandler(event:Event):void 
{ 
    trace("user canceled the download"); 
} 

private function completeHandler(event:Event):void 
{ 
    trace("download complete"); 
} 

private function ioErrorHandler(event:IOErrorEvent):void 
{ 
    trace("ioError occurred"); 
} 
+0

工作不適合MEH – 2015-07-09 08:21:31