Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get with geturl and "get" method 1

Status
Not open for further replies.

sandravega

Programmer
Feb 10, 2004
43
0
0
AR
Hi, I want something as simple as:

having a flash button, with this code:

on (press) {
sec = "mysection";
getURL("pagina2.htm", "_self", "GET");
}


and having pagina2.htm with this other code (some javascript here, just to read the querystring)


<script type="text/javascript">
function getFieldValue (strFieldName)
{
var strFieldValue;
var objRegExp = new RegExp(strFieldName + "=([^&]+)","gi");

if (objRegExp.test(location.search))
strFieldValue = unescape(RegExp.$1);
else strFieldValue="mongo";

return strFieldValue;

}
alert (getFieldValue ('sec'));
</script>

This is supposed to give a javascript dialog box saying "mysection", mean, the value from the var "sec" set in the caller flash script.

But I can`t get with it.

Of course, if I call the pagina2.htm with the url

pagina2.htm?sec="whatever"

I get the dialog box saying "whatever", the javascript stuff is just to capture the querystring var. My goal is to send a "get" from flash that can be readable from asp, php or html code... and I can`t.

Any ideas?

Sandra

By the way: some of you, when post some code, send it with a special format that makes de answer more readable... I wonder how do you do that

Thank your everybody

 
This is one way.... Place the javascript in the page that houses the Flash movie.

Button action is this:

Code:
on(release){
   sec = "mysection";
   getURL("javascript:getFieldValue(" + sec +")");
}

To make your life easier for the purposes of testing just do this in your javascript function:

Code:
<script language=javascript>
function getFieldValue(strFieldName){
   alert(strFieldName);
}

Worry about parsing it once you are sure you are getting it.

Hope it helps!

Wow JT that almost looked like you knew what you were doing!
 
And the way to format code is to enclose it in these tags:

Code:
[code]code goes here [/ code]

...only without the extra space on the end code tag (I had to add it in so that the page would show the tag and not interpret it). Click the 'process TGML' link at the bottom of the input box to see all of the options available.
 
Thank you both!
some further question to you, pixl8r:
I couldn´t use the javascript in the page that holds the movie because I needed the var to be send across pages, but I really ended using
Code:
 getURl("javascript:window.location("pagina2.htm?sec=\"mysection\"")
and that get the work done, so that was the answer, but...
I'm still curious...
what are the methods "GET" and "POST" for, if I have to send my variables always by Javascript? I read that they where about to send variables in one of the two ways available; I also read in some other thread in this forum that those methods are supposed to send "every" variable in the movie... I just don't get it. Are they completely useless?

Thank you again,

Sandra
 
No Get and Post are very useful if you are using a Server Side code. (ASP, JSP,PHP,etc...)

"GET" appends the variables to the URL address. (example:
"POST" passes the variables in the http header, so they are hidden from the browser. Post also allows for more information to be sent, where Get is limited.

You could probably use these if in your javascript you get the location.href value and parse it for the variables.

Wow JT that almost looked like you knew what you were doing!
 
Ajhá!
Let me ask just a little more... to be sure I understand this... I'm afraid I'm being a little stupid, but I tried many times with the GET and the POST methods from flash to send variables to PHP, ASP or in this last case, to Javascript... and I coudn't get it working. Never.

So, question 1)
Say I want to send a variable using GET, shoud I write

Code:
geturl("[URL unfurl="true"]http://mysite.com?myvar=wow","_self","GET");[/URL]

or
Code:
myvar="wow";
geturl("[URL unfurl="true"]http://mysite.com","_self","GET");[/URL]

And , question 2)
if it is working fine, Am I suppose to see in the url in my IE like this


or like this?


Question 3)
Do you have any working example?

Thank you. Sorry for my uneasyness to understand

Sandra
 
If you did not have a form and wanted to define a variable to pass you would use the second. Otherwise it is as below.

The correctly formatted string (in your browser using GET) would be:
As a quick example create a new movie. Add a dynamic text box to the stage. In the properties for that text box type myVar into the var box.

Next create a simple button. I usually just draw a rectangle, select it and convert it to a symbol. (be sure to select button).

Single click on the button and add the following actionscript:

Code:
on(release){
   getURL("[URL unfurl="true"]http://localhost/FormAction.asp,"_blank","GET");//replace[/URL] with your local URL) Using blank for now.
}

Now create a very simple ASP page (called "FormAction.asp") to view the result.

Code:
<%
strVar = request.querystring("myVar")'request.form for POST
response.write "myVar = "& myVar
%>

Run the flash movie and enter something in the text field. Then press the button. You will get a one line web page in a new window that says "myVar = thevalueyouentered".

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Now it works!
The javascript I posted in the first mail uses the property

"location.search" instead of "location.href", wich you suggested. That was why it didn´t work

Thank you so much.

Sandra
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top