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;
}
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;
}
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 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%40hotma il%2Ecom&n ame=Tony%2 0Smith
The following will give the request string:
email=tony%2Esmith%40hotma
var myLoadVars:LoadVars = new LoadVars();
myLoadVars.name = "Tony Smith";
myLoadVars.email = "tony.smith@hotmail.com";
trace(myLoadVars.toString());
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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[se x]=M&user[ dob]=5/12/ 1956&pasti mes[0]=gol f&pastimes [1]=opera& pastimes[2 ]=poker&pa stimes[3]= rap&childr en[bobby][ age]=12&ch ildren[bob by][sex]=M &children[ sally][age ]=8&childr en[sally][ sex]=F&fla gs_0=CEO";
after using the escape function:
var my_var = escape(my_querystring);
user%5Bname%5D%3DBob%20Smi th%26user% 5Bage%5D%3 D47%26user %5Bsex%5D% 3DM%26user %5Bdob%5D% 3D5%2F12%2 F1956%26pa stimes%5B0 %5D%3Dgolf %26pastime s%5B1%5D%3 Dopera%26p astimes%5B 2%5D%3Dpok er%26pasti mes%5B3%5D %3Drap%26c hildren%5B bobby%5D%5 Bage%5D%3D 12%26child ren%5Bbobb y%5D%5Bsex %5D%3DM%26 children%5 Bsally%5D% 5Bage%5D%3 D8%26child ren%5Bsall y%5D%5Bsex %5D%3DF%26 flags%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_va r'], $flash_vars);
echo $flash_vars['user']['name' ]; // prints out John Smith
if your querystring is quite complex eg
var my_querystring="user[name]
after using the escape function:
var my_var = escape(my_querystring);
user%5Bname%5D%3DBob%20Smi
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_va
echo $flash_vars['user']['name'
ASKER
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I agree to close this question and split points 63/62 as stated above.
Thanks,
Ondrej
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.
var myDataFile:LoadVars = new LoadVars();
myDataFile.variable1 = "variable1 data";
myDataFile.users_email = "me@you.com";
etc
etc