2013-07-01 77 views
3

As3 FileReference下載動態url不發送變量數據; 樣品:As3 FileReference下載動態url

downloadXls.buttonMode=true; 
import flash.net.FileReference; 
import flash.events.Event; 

var localRef:FileReference; 
var fileRequest:URLRequest= new URLRequest("http://[sitename].com/xlsexport.php?id=456"); 
downloadXls.addEventListener(MouseEvent.CLICK,downloadXlsH); 
function downloadXlsH(event:MouseEvent):void{ 
    localRef = new FileReference(); 
    localRef.addEventListener(Event.COMPLETE, completeHandler); 
    localRef.download(fileRequest, 'myfile.xls'); 
} 
function completeHandler(e:Event):void{ 
    trace('OK. Dosya Kaydedildi.'); 
} 

問題:HTTP:// [網站名稱]的.com/xls.php ID = 456 id變量不發送xlsexport.php

代碼僅僅是 「文件名= xlsexport」 變量產生我想發送一個不同的變量「id = 4545 & pass = 87665」

回答

1

你可以使用URLVariables類來做你想做的事。

創建ActionScript 3類文件(*。至於),並粘貼在它下面的代碼:

package 
{ 
    import flash.display.Sprite; 
    import flash.events.Event; 
    import flash.events.MouseEvent; 
    import flash.net.FileReference; 
    import flash.net.URLRequest; 
    import flash.net.URLRequestMethod; 
    import flash.net.URLVariables; 

    public class Download extends Sprite 
    { 
     var localRef:FileReference; 
     var urlVars:URLVariables; 
     var fileRequest:URLRequest; 

     public function Download(downloadXls:*) 
     { 
      downloadXls.buttonMode=true; 
      downloadXls.addEventListener(MouseEvent.CLICK,downloadXlsH); 
     } 

     private function downloadXlsH(event:MouseEvent):void 
     { 
      localRef = new FileReference(); 
      localRef.addEventListener(Event.COMPLETE, completeHandler); 

      urlVars = new URLVariables(); 
      urlVars.id = 456; 

      fileRequest = new URLRequest(); 
      fileRequest.method = URLRequestMethod.GET; 
      fileRequest.data = urlVars; 
      fileRequest.url = "http://[sitename].com/xlsexport.php"; 

      localRef.download(fileRequest); 
     } 

     private function completeHandler(e:Event):void 
     { 
      trace('OK. Dosya Kaydedildi.'); 
     } 
    } 
} 

而繼線呼叫它在你的Adobe Flash項目的時間表(* FLA文件)使用。

import Temp_Example4; 
var temp:Temp_Example4 = new Temp_Example4(downloadXls); 

請記住,如果你想添加多個URL變量,你必須使用的代碼以下行您的網址變量中的每一個:

nameOfYourURLVariablesInstance.yourUrlVariableName = yourUrlVariableValue; 

是這樣的:

urlVars.id = 456; 

示例ActionScript 3類文件。

此外,您還可以從以下地址下載示例項目:

4Shared -> Sample Project

SendSpace -> Sample Project

0

嘗試將URL構造爲字符串。

var _id:int = 456; 
var _pass:int = 87665; 
var _requestString:String = "http://" + sitename + ".com/xlsexport.php?id=" + _id + "&pass=" + _pass; 

var fileRequest:URLRequest= new URLRequest(_requestString); 

PS。還要確保你使用的是相同的var名稱(sitename或文件名)。

+0

不工作。 localRef.download(fileRequest,'myfile.xls'); fileRequest不發送變量 –