我正在使用一些不接受products.php?cat=10
作为目标的加载器,因为它太愚蠢了,无法确定文件名是什么以及查询字符串是什么。是否有AS3函数将解析URL并根据查询字符串中的变量返回URLRequest?
答案 0 :(得分:8)
有可能创造你所需要的一切:
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;
import flash.events.Event;
// the path to the backend file
var url : String = 'http://youdomain.com/filepath.php';
// url variables all which will appear after ? sign
var urlVariables : URLVariables = new URLVariables ();
urlVariables['varname'] = 'varvalue';
urlVariables['varname1'] = 'varvalue1';
// here you can add as much as you need
// creating new URL Request
// setting the url
var request : URLRequest = new URLRequest ( url );
// setting the variables it need to cary
request.data = urlVariables;
// setting method of delivering variables ( POST or GET )
request.method = URLRequestMethod.GET;
// creating actual loader
var loader : URLLoader = new URLLoader ();
loader.addEventListener( Event.COMPLETE, handleLoaderComplete )
loader.load ( request );
答案 1 :(得分:5)
您可以使用URLVariables.decode()将查询字符串转换为URLVariables对象的属性:
function getProperURLRequest ( url : String ) : URLRequest
{
var input : Array = url.split("?");
var urlVars : URLVariables = new URLVariables ();
urlVars.decode( input[1] );
var urlReq : URLRequest = new URLRequest ( input[0] );
urlReq.data = urlVars;
urlReq.method = URLRequestMethod.GET;
return urlReq;
}
答案 2 :(得分:0)
products.php?cat=1
等网址应该没有问题。也许你只是忘了把crossdomain.xml放在你的服务器上。我想,这是使用URLRequest