Link to home
Start Free TrialLog in
Avatar of okexchange
okexchange

asked on

Limits of url string for LoadVars.load() in AS2 and AS3?

I have a problem with the long url string in LoadVars. It all works with short url, but fails with long url of several thousands of characters. Is there any solution? Is ActionScript3 better in this respect?

Example:

If I call getmyDataFile with urlString longer than 879 characters it will fail. Is it not a poor performance of Flash? I need to use longer url strings in GET or POST in the long form when I call myFormProcessot.php.

var myDataFile:LoadVars = new LoadVars();

function getmyDataFile(urlString) {
    myDataFile.load(urlString);
}

myDataFile.onData = function(rawData) {
    if(rawData) {
       somedataprocessor();
    }else{
       show error;
    }
Avatar of Rob
Rob
Flag of Australia image

The url shouldn't need to be that long... The LoadVars object expects you to set up name / value pairs eg

var myDataFile:LoadVars = new LoadVars();

myDataFile.variable1 = "variable1 data";
myDataFile.users_email = "me@you.com";
etc
etc
Avatar of okexchange
okexchange

ASKER

Thanks tagit,

I already have string of variables which will be result of your suggestion. This string is long and will be long even if I do what you suggested.
My url string constructed by your example will be:

http://mydomain.com/formProcessor.php?variable1=variable1+data&users_email=me@you.com&variable2=variable2+data&variable3=.... etc

The above url string gets longer with more variables and I have plenty of them and the are not same every time. Actually this url string is taken from HTML Form after submit button was hit and can be used in ActionScript2 same way as method=GET in HTML Form.
Back to my question, the only problem is that in ActionScript2 the string has limitation whereas in normal browser I did not hit any limitation. If I put the long url string, which does not work in Flash ActionScript2, to the address field in any browser, it will return right response from formProcessor.php and requested page is rendered in the browser.
Flash somehow puts the restriction on the length of url string for LoadVars. At least if they put the restriction very high and not bellow 1000 chars. You can hit this limit very soon with not so astronomical number of variables.
The question is, is there any way round? For example using AS3 and URLRequest class loader.load(url). But this is made for external display asset.

I need to understand why you are passing the url to the LoadVars object instead of building it as I suggested in my last post.  If you are doing this then why do you pass the url to the LoadVars object as it will have already stored the url as indicated below

The following will give the request string:

email=tony%2Esmith%40hotmail%2Ecom&name=Tony%20Smith

var myLoadVars:LoadVars = new LoadVars();

myLoadVars.name = "Tony Smith";
myLoadVars.email = "tony.smith@hotmail.com";

trace(myLoadVars.toString());

Open in new window

SOLUTION
Avatar of moagrius
moagrius
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Tagit,

Your suggestion basicly works, but not for my purpose. I do not know the url string in advance and I cannot construct it. It is constructed in HTML page and I just read the string the form is sending to the server and try to send the same thing using Flash and ActinScript without making Form in Flash. This way the form can be made in HTML and result is processed by ActionScript. The whole thing looks like ordinary HTML page and Flash works in the background. Flash is not just prety animation, but also full blown programing language specially when AS3 is used. Pity about limitations.

Thanks moaqrius,

I have tried your suggestion using POST instead of GET and I have the same results. The problem might be in mProjector I am using to create desktop application from .swf. I think I will chop it to managable chunks of string and send it per partes.
The LoadVars object has the limitation but another way to achieve this might be  to URL encode the urlString using the escape() function to make it something like this:

if your querystring is quite complex eg

var my_querystring="user[name]=Bob Smith&user[age]=47&user[sex]=M&user[dob]=5/12/1956&pastimes[0]=golf&pastimes[1]=opera&pastimes[2]=poker&pastimes[3]=rap&children[bobby][age]=12&children[bobby][sex]=M&children[sally][age]=8&children[sally][sex]=F&flags_0=CEO";

after using the escape function:
var my_var = escape(my_querystring);
user%5Bname%5D%3DBob%20Smith%26user%5Bage%5D%3D47%26user%5Bsex%5D%3DM%26user%5Bdob%5D%3D5%2F12%2F1956%26pastimes%5B0%5D%3Dgolf%26pastimes%5B1%5D%3Dopera%26pastimes%5B2%5D%3Dpoker%26pastimes%5B3%5D%3Drap%26children%5Bbobby%5D%5Bage%5D%3D12%26children%5Bbobby%5D%5Bsex%5D%3DM%26children%5Bsally%5D%5Bage%5D%3D8%26children%5Bsally%5D%5Bsex%5D%3DF%26flags%5F0%3DCEO

using LoadVars():
var myLoadVars:LoadVars = new LoadVars();
myLoadVars.qry = my_var;

then in PHP you can access this in the $_REQUEST variable:
parse_str($_REQUEST['my_var'], $flash_vars);

echo $flash_vars['user']['name']; // prints out John Smith
Thanks tagif,

I have done this URL  encode, but later I found that Flash does it anyway before it sends to the server. So I stopped it and gained some charactes to spare. URL encoded string is longer. It did not make any difference on limitation.

Thanks about PHP coding I will test it tomorrow.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree to close this question and split points 63/62 as stated above.

Thanks,
              Ondrej
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.