AS3 URL字符串 - > URLRequest

A-O*_*-OK 4 string url actionscript-3

我正在使用一些不接受products.php?cat=10作为目标的加载器,因为它太愚蠢而无法弄清楚文件名是什么以及查询字符串是什么.是否有AS3函数将解析URL并根据查询字符串中的变量返回URLRequest?

Jev*_*jev 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 );
Run Code Online (Sandbox Code Playgroud)


wel*_*rat 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;
}
Run Code Online (Sandbox Code Playgroud)