;

PDA

Click to See Complete Forum and Search --> : getURL POST & GET won't work


marexposed
05-06-2008, 04:12 AM
I've put the same variable name with the same content all over the flash movie, even inside the on(release).
Then I go:
on (release) {
var picho:String = "hola";
getURL("http://myurl/index.php", "GET");
}
Before that I used "_blank" in between, but I took it away as I read was causing problems to someone. Same thing:
The php script doesn't get anything, the address bar doesn't show any variables and I ran out of searching options for the solution.
This is a Flash 8 movie loaded into CS3.

Thanks for any suggestion.

webdreamer
05-06-2008, 05:27 AM
Can you tell us what your trying to do?

marexposed
05-06-2008, 08:13 AM
Yes, I'm just trying to POST OR GET the flash movie variables over the internet and to get to process them at the other end with the page index.php hosted at http://myurl

According to flash help, this will do it:

The following ActionScript uses POST to send variables in the HTTP header. Make sure you test your documents in a browser window, because otherwise your variables are sent using GET:

var firstName:String = "Gus";
var lastName:String = "Richardson";
var age:Number = 92;
getURL("http://www.adobe.com", "_blank", "POST");

But it doesn't to me, either using GET or POST.

marexposed
05-06-2008, 08:28 AM
Quick reply doesn't work? I just lost my reply. Ok, let's go again:
I'm just trying to GET or POST some flash movie variables over the internet and to get to process them at the other end by the file index.php hosted at http://myurl.

According to flash help, this will do it:
The following ActionScript uses POST to send variables in the HTTP header. Make sure you test your documents in a browser window, because otherwise your variables are sent using GET:

var firstName:String = "Gus";
var lastName:String = "Richardson";
var age:Number = 92;
getURL("http://www.adobe.com", "_blank", "POST");

But it doesn't to me. The url is correctly opened but variables are safely kept inside the swf, no indication they'll be released whatsoever to the outside world.

a_modified_dog
05-06-2008, 08:28 AM
if you are trying to send the variable picho, use -

var picho:String = "hola";
getURL("http://myurl/index.php?picho="+picho);

test in browser as appended vars fail silently in authoring environment

marexposed
05-06-2008, 08:31 AM
ok, my posts might be delayed somewhere, I assume they are on their way while I reply to a_modified_dog.
Thanks, but, if I want to post them hidden in the http header... what should I do?

marexposed
05-06-2008, 08:32 AM
what the...! The posts are not queued are they?... ok, I'll go again with my reply to webdreamer:

Quick reply doesn't work? I just lost my reply. Ok, let's go again:
I'm just trying to GET or POST some flash movie variables over the internet and to get to process them at the other end by the file index.php hosted at http://myurl.

According to flash help, this will do it:
The following ActionScript uses POST to send variables in the HTTP header. Make sure you test your documents in a browser window, because otherwise your variables are sent using GET:

var firstName:String = "Gus";
var lastName:String = "Richardson";
var age:Number = 92;
getURL("http://www.adobe.com", "_blank", "POST");

But it doesn't to me. The url is correctly opened but variables are safely kept inside the swf, no indication they'll be released whatsoever to the outside world.

marexposed
05-06-2008, 08:33 AM
Ok, third try the post has got there. Sorry if my previous two appear after. Will look as I'm spamming.

a_modified_dog
05-06-2008, 08:39 AM
getURL("http://myurl/index.php?picho="+picho, "POST");

// or

lv = new LoadVars();
lv.picho = "hola";
lv.sendAndload("http://myurl/index.php", lv, "POST");
lv.onLoad = function(){
trace(unescape(this)); // catch returned values or errors from php
};

marexposed
05-06-2008, 08:47 AM
Ok, I'll try that, modified_dog, but if that works I'll get very annoyed with flash help writers, because what they say is different.

toltec7
05-06-2008, 08:53 AM
Create a new movie clip like...

var movClip:MovieClip = _root.createEmptyMovieClip("mov", _root.getNextHighestDepth());

movClip.picho = "hola";
movClip.getURL("address", "POST");

marexposed
05-06-2008, 09:14 AM
toltec7, I'm not very skilled at flash, so I've added your code into the on(release) method of the main movie, like this:

on (release) {
var movClip:MovieClip = _root.createEmptyMovieClip("mov", _root.getNextHighestDepth());

movClip.picho = "hola";
movClip.getURL("http://myurl/index.php", "GET");
}

But it doesn't even navigate to the url (let alone sending the variables :) )

Regarding a_modified_dog's example, even I define the variable picho RIGHT BEFORE the getURL statement, the content seems to be plain blank:

on (release) {
var picho:String = "hola";
getURL("http://megaclor.110mb.com/index.php?url="+picho, "GET");
}

I'm using GET to have at least the chance of seeing the variable going on the address bar.

Is adobe flash kind of criptic, or is just me?

webdreamer
05-06-2008, 09:25 AM
Hey i got know replies to say this thread was still active!
Anyways...
Dont know how you guys have got lost here.
this is all you need.

on (release) {
getURL("http://megaclor.110mb.com/index.php?someVar=hello", "_blank");
}

or if you want to use some populated var

on (release) {
var picho = "hello"
getURL("http://megaclor.110mb.com/index.php?someVar="+picho, "_blank");
}
//More than one var
on (release) {
var picho1 = "hello"
var picho2 = "you"
getURL("http://megaclor.110mb.com/index.php?someVar1="+picho1+"&someVar2="+picho2, "_blank");
}


Hope that clears things up for you.

marexposed
05-06-2008, 09:52 AM
Ok, your code does work, webdreamer, which leaves me with the enigma of why if they define it everywhere as ":String" wont work as expected. After all, a type declaration after the name is perfectly logic as I understand it. But hey...!
Now, what if I want to send, not picho, but something like root.loaderInfo.url?
This doesn't work:

on (release) {
var picho = root.loaderInfo.url;
getURL("http://myurl/index.php?url="+picho, "GET");
}

Neither this does:

on (release) {
getURL("http://myurl/index.php?url="+root.loaderInfo.url, "GET");
}

Isn't root.loaderInfo.url the right way to obtain the url being navigated by the browser window that contains the swf being played.

I'm just trying my swf to say to my server: "Hey, I'm *this* swf and I've been clicked while playing myself to a user who was browsing *this* url".

toltec7
05-06-2008, 09:59 AM
toltec7, I'm not very skilled at flash, so I've added your code into the on(release) method of the main movie, like this:

on (release) {
var movClip:MovieClip = _root.createEmptyMovieClip("mov", _root.getNextHighestDepth());

movClip.picho = "hola";
movClip.getURL("http://myurl/index.php", "GET");
}

But it doesn't even navigate to the url (let alone sending the variables :) )

you should do that code in timeline I guess...
so name you button (instance name)
and do this on _root or some other timeline...

button.onRelease = function () {

var movClip:MovieClip = _root.createEmptyMovieClip("mov", _root.getNextHighestDepth());

movClip.picho = "hola";
movClip.getURL("http://myurl/index.php", "POST");

}

that really should work if you wanna send with POST.
you can send with GET by adding a query string like the other guy explained...

webdreamer
05-06-2008, 10:01 AM
Ok, your code does work, webdreamer, which leaves me with the enigma of why if they define it everywhere as ":String" wont work as expected. After all, a type declaration after the name is perfectly logic as I understand it. But hey...!
Now, what if I want to send, not picho, but something like root.loaderInfo.url?
This doesn't work:

on (release) {
var picho = root.loaderInfo.url;
getURL("http://myurl/index.php?url="+picho, "GET");
}

Neither this does:

on (release) {
getURL("http://myurl/index.php?url="+root.loaderInfo.url, "GET");
}

Isn't root.loaderInfo.url the right way to obtain the url being navigated by the browser window that contains the swf being played.

I'm just trying my swf to say to my server: "Hey, I'm *this* swf and I've been clicked while playing myself to a user who was browsing *this* url".

it should be _root.blah...
not root.blah...

a_modified_dog
05-06-2008, 10:24 AM
i personally favour the LoadVars method as getURL is somewhat outdated :D
here is a link to see a working file (php included)

http://www.jackleaman.co.uk/temp/vars.html

webdreamer
05-06-2008, 10:33 AM
i personally favour the LoadVars method as getURL is somewhat outdated :D
here is a link to see a working file (php included)

http://www.jackleaman.co.uk/temp/vars.html
I think it's depends on what he's looking to do with the vars. I mean what if he wants to populate a html based form fields with data passed in the url?

Thats the only reason i can see my self using the suggested method.

in the other hand if he's doing something like a contact form the sendAndLoad() would be the better method even though some template sites out there seem to do the suggest method.

marexposed
05-06-2008, 10:34 AM
I wish I say "it did work", but it didn't unfortunately.
I tried both examples as I did before, this time adding the underscore as prefix. As usual I "export movie", I upload to the server, I reload the page that contains the swf, I click on it and I get a popup browser window navigating to the address stated in getURL, but I only get an empty string next to the "url=" in the browser's address bar.

Neither _root.loaderInfo.url or root.loaderInfo.url seems to provide a value. At least not as I'm using them.

Any (more) ideas?

marexposed
05-06-2008, 10:40 AM
Ok a_modified_dog, I'll try your code now.

Wait! Is your code informing where the swf is hosted or where is being played? Because if it's the former, that's not what I'm looking for. I need to know the address of the web-page where the swf is being played.

Anyway, I still will try the loadvars method.

webdreamer
05-06-2008, 10:41 AM
Sounds like _root.loaderInfo.url is not holding any data.
What are you expecting to see?

Can you post your fla?
Got to get to the bottom of this.

marexposed
05-06-2008, 11:14 AM
Ok, I tried the LoadVars. I wouldn't quite know where to place the code, as it isn't as evident as an event handler. I just deleted the code in my previous event handler and placed the code somewhere that reads "link : Frame 1". The code goes:

var picho:String;
botonurl.onRelease = function() {
picho = _root.loaderInfo.url;
sendVar(picho);
};

function sendVar(param) {
lv = new LoadVars();
lv.picho = param;
lv.sendAndLoad("http://myweb/index.php",lv,"POST");
lv.onLoad = function() {
tracer.text = this.varReceived;
};
};

This doesn't even open a popup (nor no-popup) window with http://myweb.

webdreamer
05-06-2008, 11:16 AM
What is it your trying to do with the variables being passed?

marexposed
05-06-2008, 11:37 AM
webdreamer I'm expecting to see the address of the webpage which has loaded the swf and is playing it.
Let's say you have 2 webpages http://webA, http://webB, loading the same swf from a third host. I need the swf, on click, to say "I'm playing on a browser navigating webA" or "I'm playing on a browser navigating webB".

webdreamer
05-06-2008, 12:07 PM
I dont see a problem. i have it working here (http://www.scotflash.co.uk/test/theUrl.html)


but1.onRelease = function() {
trace("clicked one_btn");
trace(this._url);
getURL("http://www.scotflash.co.uk/test/index.php?urlVar="+this._url);
};

marexposed
05-06-2008, 12:52 PM
Yes webdreamer, but this._url refers to the address where the swf is hosted, not the address of the container. I'm looking for the address of the container (http://webA or http://webB).

x_liu
03-26-2009, 05:13 PM
I was having similar problem, except that I NEED to get the data in POST method to prefill another webform. toltec7's code worked miracle for me, only thing I needed to change is adding "_blank" in the getURL call.

movClip.getURL("http://myurl/index.php", "_blank", "POST");

THANK YOU!

you should do that code in timeline I guess...
so name you button (instance name)
and do this on _root or some other timeline...

button.onRelease = function () {

var movClip:MovieClip = _root.createEmptyMovieClip("mov", _root.getNextHighestDepth());

movClip.picho = "hola";
movClip.getURL("http://myurl/index.php", "POST");

}

that really should work if you wanna send with POST.
you can send with GET by adding a query string like the other guy explained...

e_tit
04-01-2009, 12:24 PM
marexposed, It has to be _url. You are missing the underscore.

MyFriendIsATaco
04-01-2009, 12:57 PM
It's impossible to retrieve the url that the swf is embedded on without some Javascript trickery. And it'll only work if the swf is embedded with the "allowscriptaccess" variable set to "always".import flash.external.ExternalInterface;

var r:String = ExternalInterface.call("function(){return window.location.href}");
trace(r); //r will be exactly what it says in the browser's address bar.

MyFriendIsATaco
04-01-2009, 01:02 PM
I was having similar problem, except that I NEED to get the data in POST method to prefill another webform. toltec7's code worked miracle for me, only thing I needed to change is adding "_blank" in the getURL call.

movClip.getURL("http://myurl/index.php", "_blank", "POST");

THANK YOU!

You should always use some form of sendAndLoad. Using getURL is real old. To do what you want to do, you'd use almost the same exact syntax, but instead of sendAndLoad, you'd use just send. LoadVars.send().