4

I'm using some loader that doesn't accept products.php?cat=10 as a target because it's too stupid to figure out what's the file name and what's the query string. Is there an AS3 function that will parse an URL and return a URLRequest based on variables in the query string?

1
  • What error are you receiving? Commented May 22, 2011 at 9:02

3 Answers 3

8

There is possibility to create all you need:

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 );
Sign up to request clarification or add additional context in comments.

3 Comments

yes, but what if url = 'filepath.php?var1=value1' ? I know how to make a loader but I need a function that will make a loader from an existing url that already has a query string
sorry, I need a function that will make an URLrequest from an url that already has a query string. Does AS3 have that?
From my expirience there should be absolutely no problem to add the variables like you want. you can do my described way or lust load like you want: "='filepath.php?var1=value1'" You getting any error messages or something from the loader you are trying to use?
5

You can use URLVariables.decode() to convert the query string into properties of the URLVariables object:

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;
}

Comments

0

There should be no problems with urls like products.php?cat=1. Maybe you just forgot to put crossdomain.xml on your server. I suppose, it's the most frequent error while using URLRequest

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.