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:// [sitename] .com / xls.php?id = 456 id变量不发送xlsexport.php
代码只是“filename = xlsexport”变量产生一个变量我想发送一个不同的“id = 4545& pass = 87665”
答案 0 :(得分:1)
您可以使用URLVariables类执行您想要的操作。
创建一个ActionScript 3类文件(* .as)并在其中粘贴以下代码:
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);
请记住,如果您想添加多个网址变量,则必须为每个网址变量使用以下代码行:
nameOfYourURLVariablesInstance.yourUrlVariableName = yourUrlVariableValue;
类似的东西:
urlVars.id = 456;
示例ActionScript 3类文件中的。
此外,您可以从以下地址下载示例项目:
答案 1 :(得分: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或filename)。